How would i go about finding the number of \'zero\' bits in C++. Suppose I have an integer;
int value = 276;
For which I have the bits 100010
By far the most obvious solution is a lookup table.
/* Assuming CHAR_BITS == 8 */ int bitsPerByte[256] = { 8, 7, 7, 6, /* ... */ }; int bitsInByte(unsigned char c) { return bits[c]; }