Question: Write a function named bitCount() in bitcount.c that returns the number of 1-bits in the binary representation of its unsigned integer argument. For example, -->59
Write a function named bitCount() in bitcount.c that returns the number of 1-bits in the binary representation of its unsigned integer argument. For example, -->59 = 0b011 1011.<-- --> The number of 1-bits of 59 is 5.<--
#includeint bitCount (unsigned int n); int main ( ) { printf ("# 1-bits in base 2 representation of %u = %d, should be 0 ", 0, bitCount (0)); printf ("# 1-bits in base 2 representation of %u = %d, should be 1 ", 1, bitCount (1)); printf ("# 1-bits in base 2 representation of %u = %d, should be 16 ", 2863311530u, bitCount (2863311530u)); printf ("# 1-bits in base 2 representation of %u = %d, should be 1 ", 536870912, bitCount (536870912)); printf ("# 1-bits in base 2 representation of %u = %d, should be 32 ", 4294967295u, bitCount (4294967295u)); return 0; } int bitCount (unsigned int n) { /* your code here */ }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
