X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=common%2Futil.c;h=9d8fb93219d97d725ec19410033b5cd86647c348;hb=6215727b0bd827a18456b21a26d6175abe365ada;hp=644301fe89d6a204a17979125944b3ef0f84a177;hpb=3c822b511e7af60332a7e5a938c08bafb2516ba3;p=max%2Ftmk_keyboard.git diff --git a/common/util.c b/common/util.c index 644301fe..9d8fb932 100644 --- a/common/util.c +++ b/common/util.c @@ -22,7 +22,7 @@ uint8_t bitpop(uint8_t bits) { uint8_t c; for (c = 0; bits; c++) - bits &= bits -1; + bits &= bits - 1; return c; /* const uint8_t bit_count[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; @@ -30,6 +30,14 @@ uint8_t bitpop(uint8_t bits) */ } +uint8_t bitpop16(uint16_t bits) +{ + uint8_t c; + for (c = 0; bits; c++) + bits &= bits - 1; + return c; +} + // most significant on-bit - return highest location of on-bit uint8_t biton(uint8_t bits) {