This repo is archived. You can view files and clone it, but cannot push or open issues or pull requests.
2010-10-27 11:51:45 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2010-12-07 16:47:57 +00:00
|
|
|
// bit population
|
2010-10-27 11:51:45 +00:00
|
|
|
int bitpop(uint8_t bits)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
for (c = 0; bits; c++)
|
|
|
|
bits &= bits -1;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-12-07 16:47:57 +00:00
|
|
|
// most significant on-bit
|
2010-10-27 11:51:45 +00:00
|
|
|
int biton(uint8_t bits)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
if (bits >> 4) { bits >>= 4; n += 4;}
|
|
|
|
if (bits >> 2) { bits >>= 2; n += 2;}
|
|
|
|
if (bits >> 1) { bits >>= 1; n += 1;}
|
|
|
|
return n;
|
|
|
|
}
|