From: Nathael Pajani Date: Thu, 19 Nov 2020 18:48:20 +0000 (+0100) Subject: Fix bits_set X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=04fb4d4fc795c999afabdc27e02e13b9c6df6583;p=soft%2Flpc122x%2Fcore Fix bits_set --- diff --git a/lib/utils.c b/lib/utils.c index 96ad730..96ab676 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -93,14 +93,10 @@ uint8_t bits_set(uint32_t x) static const uint8_t bval_bsets[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4}; uint8_t r = 0; /* Accumulator for the total bits set in x */ - r = bval_bsets[x & 0xFF]; - x >>= 8; - r += bval_bsets[x & 0xFF]; - x >>= 8; - r += bval_bsets[x & 0xFF]; - x >>= 8; - r += bval_bsets[x & 0xFF]; - + while (x) { + r += bval_bsets[x & 0x0F]; + x >>= 4; + } return r; }