diff options
author | tmk <nobody@nowhere> | 2013-03-05 15:45:15 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2013-03-05 15:45:15 +0900 |
commit | 38bbe976e00a9a7bf6f8157016717e80503bf6a9 (patch) | |
tree | 9113cd57c1bff3deef394ee966e2fdac8731a244 /common/util.c | |
parent | 1720cf34caa518a2cf85f286d1ca077ebe1a1451 (diff) | |
parent | 5808317b694004c43a6e0f76e9715415cce19a25 (diff) |
Merge branch 'overlays'
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index 9d8fb93219..ff1926d7d1 100644 --- a/common/util.c +++ b/common/util.c @@ -39,6 +39,7 @@ uint8_t bitpop16(uint16_t bits) } // most significant on-bit - return highest location of on-bit +// NOTE: return 0 when bit0 is on or all bits are off uint8_t biton(uint8_t bits) { uint8_t n = 0; @@ -47,3 +48,13 @@ uint8_t biton(uint8_t bits) if (bits >> 1) { bits >>= 1; n += 1;} return n; } + +uint8_t biton16(uint16_t bits) +{ + uint8_t n = 0; + if (bits >> 8) { bits >>= 8; n += 8;} + if (bits >> 4) { bits >>= 4; n += 4;} + if (bits >> 2) { bits >>= 2; n += 2;} + if (bits >> 1) { bits >>= 1; n += 1;} + return n; +} |