Veritas (Georgia) interview question

write code to count the number of bits in a byte

Interview Answer

Anonymous

25 Mar 2010

use a bit mask (0x01) and btiwise & it with the number. Keep left shifting the bitmask 8 times and increment count each time the answer of the bitwise & is 1.