aboutsummaryrefslogtreecommitdiff
path: root/common/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/util.c')
-rw-r--r--common/util.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c
index 9d8fb9321..ff1926d7d 100644
--- a/common/util.c
+++ b/common/util.c
@@ -39,6 +39,7 @@ uint8_t bitpop16(uint16_t bits)
39} 39}
40 40
41// most significant on-bit - return highest location of on-bit 41// most significant on-bit - return highest location of on-bit
42// NOTE: return 0 when bit0 is on or all bits are off
42uint8_t biton(uint8_t bits) 43uint8_t biton(uint8_t bits)
43{ 44{
44 uint8_t n = 0; 45 uint8_t n = 0;
@@ -47,3 +48,13 @@ uint8_t biton(uint8_t bits)
47 if (bits >> 1) { bits >>= 1; n += 1;} 48 if (bits >> 1) { bits >>= 1; n += 1;}
48 return n; 49 return n;
49} 50}
51
52uint8_t biton16(uint16_t bits)
53{
54 uint8_t n = 0;
55 if (bits >> 8) { bits >>= 8; n += 8;}
56 if (bits >> 4) { bits >>= 4; n += 4;}
57 if (bits >> 2) { bits >>= 2; n += 2;}
58 if (bits >> 1) { bits >>= 1; n += 1;}
59 return n;
60}