BlackBerry interview question

Wit only using Bitwise operations, write a program that returns the number of zeros in a binary number. Like 01010010 will return 5.

Interview Answer

Anonymous

3 Apr 2013

Think popcount and use its inverse: uint16_t num = 0x1F0A; numZeros = sizeof(num) * CHAR_BIT - popcount(num);