Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.c 309B

123456789101112131415161718
  1. #include "util.h"
  2. int bitpop(uint8_t bits)
  3. {
  4. int c;
  5. for (c = 0; bits; c++)
  6. bits &= bits -1;
  7. return c;
  8. }
  9. int biton(uint8_t bits)
  10. {
  11. int n = 0;
  12. if (bits >> 4) { bits >>= 4; n += 4;}
  13. if (bits >> 2) { bits >>= 2; n += 2;}
  14. if (bits >> 1) { bits >>= 1; n += 1;}
  15. return n;
  16. }