Ben Fossen
Ben Fossen

Reputation: 1007

Ideas for making a function for counting number of zero's in a bit string in C?

Can I make a function int bitParity(int x) that returns 1 if x contains an odd number of 0's using only these operators? ! ~ & ^ | + << >>

Upvotes: 0

Views: 188

Answers (1)

Krab
Krab

Reputation: 2148

Hey, it was exactly three clicks. google -> 1.st result - wiki/Parity_bit -> external link -> http://graphics.stanford.edu/~seander/bithacks.html#ParityNaive

Upvotes: 2

Related Questions