From e324fa29187dff7868d9d7fd378e0e46d77107a5 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 16 Feb 2013 04:05:58 +0900 Subject: Rewrite layer action with layer_switch --- common/util.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'common/util.c') 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; +} -- cgit v1.2.3