logo CodeStepByStep logo

cmp_bits

Author: Cynthia Lee (on 2016/11/03)

Write a function named cmp_bits that accepts two int arguments a and b, and compares the number of "on" bits (number of 1s) between them. Returns a negative result if the bitwise representation of a has fewer 1s than b, a positive result if a has more 1s than b, and zero if both have the same number of 1s. For example, if a is 5 (binary 00000000000000000000000000000101) and b is 32 (binary 00000000000000000000000000010000), then cmp_bits returns any positive number (for example, it could return 1).

Function: Write a C function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.