summaryrefslogtreecommitdiff
path: root/common/util.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-02-16 04:05:58 +0900
committertmk <nobody@nowhere>2013-02-16 04:08:31 +0900
commite324fa29187dff7868d9d7fd378e0e46d77107a5 (patch)
treea72966995df47eef01ced9873c14f972de8af069 /common/util.c
parent0142b571c46c7db314063615c956cbc5ec9720f1 (diff)
Rewrite layer action with layer_switch
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 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;
+}