Add bitpop16() in util.c.

pull/12/head
tmk 12 years ago
parent 83f0e800e5
commit 94b4fba6e6

@ -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 // most significant on-bit - return highest location of on-bit
uint8_t biton(uint8_t bits) uint8_t biton(uint8_t bits)
{ {

@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef UTIL_H #ifndef UTIL_H
#define UTIL_H 1 #define UTIL_H
#include <stdint.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 bitpop(uint8_t bits);
uint8_t bitpop16(uint16_t bits);
uint8_t biton(uint8_t bits); uint8_t biton(uint8_t bits);
#endif #endif

Loading…
Cancel
Save