Question: C programming problem The code should only contain a single function that reverses the bits of a given integer. It currently has two functions: unsigned

C programming problem

The code should only contain a single function that reverses the bits of a given integer. It currently has two functions: unsigned int reverseBits(unsigned int num) and int main()

Please modify the code below so that it works with only one function. It must be a function prototype just like unsigned int reverseBits(unsigned int num)

( do not include int main())

unsigned int reverseBits(unsigned int num) { unsigned int NO_OF_BITS = sizeof(num) * 8; unsigned int reverse_num = 0; int i; for (i = 0; i < NO_OF_BITS; i++) { if((num & (1 << i))) reverse_num |= 1 << ((NO_OF_BITS - 1) - i); } return reverse_num; } /* Driver function to test above function */ int main() { unsigned int x = 2; printf("%u", reverseBits(x)); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!