]> git.gir.st - tmk_keyboard.git/blob - util.c
Synchronous USART support for PS/2 on V-USB stack
[tmk_keyboard.git] / util.c
1 #include "util.h"
2
3 // bit population
4 int bitpop(uint8_t bits)
5 {
6 int c;
7 for (c = 0; bits; c++)
8 bits &= bits -1;
9 return c;
10 }
11
12 // most significant on-bit
13 int biton(uint8_t bits)
14 {
15 int n = 0;
16 if (bits >> 4) { bits >>= 4; n += 4;}
17 if (bits >> 2) { bits >>= 2; n += 2;}
18 if (bits >> 1) { bits >>= 1; n += 1;}
19 return n;
20 }
Imprint / Impressum