From c8b3668e487d2d35951969ccfa0c2882e96cdfec Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 20 Apr 2012 02:38:26 -0400 Subject: Get rid of magic number. --- bits.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'bits.c') diff --git a/bits.c b/bits.c index f2fc1ff9..34fd4064 100644 --- a/bits.c +++ b/bits.c @@ -13,11 +13,10 @@ #include #include #include +#include #include "bits.h" -#define BITS_PER_BYTE 8 - uint64_t ubits(char buf[], unsigned int start, unsigned int width, bool le) /* extract a (zero-origin) bitfield from the buffer as an unsigned big-endian uint64_t */ { @@ -25,16 +24,16 @@ uint64_t ubits(char buf[], unsigned int start, unsigned int width, bool le) unsigned int i; unsigned end; - /*@i1@*/ assert(width <= sizeof(uint64_t) * BITS_PER_BYTE); - for (i = start / BITS_PER_BYTE; - i < (start + width + BITS_PER_BYTE - 1) / BITS_PER_BYTE; i++) { - fld <<= BITS_PER_BYTE; + /*@i1@*/ assert(width <= sizeof(uint64_t) * CHAR_BIT); + for (i = start / CHAR_BIT; + i < (start + width + CHAR_BIT - 1) / CHAR_BIT; i++) { + fld <<= CHAR_BIT; fld |= (unsigned char)buf[i]; } - end = (start + width) % BITS_PER_BYTE; + end = (start + width) % CHAR_BIT; if (end != 0) { - fld >>= (BITS_PER_BYTE - end); + fld >>= (CHAR_BIT - end); } /*@ -shiftimplementation @*/ -- cgit v1.2.1