]> git.donarmstrong.com Git - tmk_firmware.git/commitdiff
Add bitpop16() in util.c.
authortmk <nobody@nowhere>
Sat, 24 Nov 2012 07:34:59 +0000 (16:34 +0900)
committertmk <nobody@nowhere>
Sat, 24 Nov 2012 07:34:59 +0000 (16:34 +0900)
common/util.c
common/util.h

index 644301fe89d6a204a17979125944b3ef0f84a177..9d8fb93219d97d725ec19410033b5cd86647c348 100644 (file)
@@ -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)
 {
index 87636c9710bbeb2deb38edae736fe5afd5d37e91..c3734487f9d6d78e5ff7a60b84fe3dd03e02f2d0 100644 (file)
@@ -16,7 +16,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef UTIL_H
-#define UTIL_H 1
+#define UTIL_H
 
 #include <stdint.h>
 
@@ -29,6 +29,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
 uint8_t bitpop(uint8_t bits);
+uint8_t bitpop16(uint16_t bits);
 uint8_t biton(uint8_t bits);
 
 #endif