diff options
author | tmk <nobody@nowhere> | 2013-02-16 04:20:01 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2013-02-16 04:20:01 +0900 |
commit | 998dc6c17e0b0cfe8377529a130d9c61590caf2a (patch) | |
tree | f0745fb55e970f057a862732739be4a665cdf910 /common/util.c | |
parent | f8d289e66965f99469292370c3b9200a03254f8e (diff) | |
parent | 06e4fc66edd15efa5afdcaed2102c7698b626484 (diff) |
Merge branch 'layer_switch'
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; +} |