home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 10
/
AU_CD10.iso
/
Archived
/
Updates
/
Flash
/
writeflash
/
!MakeFlash
/
c
/
bitcount
< prev
next >
Wrap
Text File
|
2000-04-01
|
1KB
|
64 lines
#include <stdio.h>
//
#include "proto.h"
#include "bitcount.h"
static int bitcnts(S32 v);
static int bitcnt(U32 v);
int bitcount_signed(S32 v1, S32 v2, S32 v3, S32 v4) {
int n, max;
max = 0;
n = bitcnts(v1); if (n > max) max = n;
n = bitcnts(v2); if (n > max) max = n;
n = bitcnts(v3); if (n > max) max = n;
n = bitcnts(v4); if (n > max) max = n;
return max;
}
int bitcount(U32 v1, U32 v2, U32 v3, U32 v4) {
int n, max;
max = 0;
n = bitcnt(v1); if (n > max) max = n;
n = bitcnt(v2); if (n > max) max = n;
n = bitcnt(v3); if (n > max) max = n;
n = bitcnt(v4); if (n > max) max = n;
return max;
}
// ----------------------------------------------------------------
int bitcnts(S32 v) {
int n;
n = 31;
if (v >= 0) {
while (((v & (1<<n)) == 0) && (n > 0)) n--;
n += 2;
} else {
while ((v & (1<<n)) && (n > 0)) n--;
n += 2;
}
return n;
}
int bitcnt(U32 v) {
int n;
n = 31;
while (((v & (1<<n)) == 0) && (n > 0)) n--;
return n+1;
}