Question: Create a C program as follows. First define a function called msb (most significant bit) that takes as input a positive non-zero integer (unsigned int)

Create a C program as follows. First define a function called msb (most significant bit) that takes as input a positive non-zero integer (unsigned int) and returns the position of the most significant bit that is set to 1. Next, write a function called lsb that takes as input a positive non-zero integer (unsigned int) and returns the position of the least significant bit that is set to 1. Note that if the unsigned integer has a single bit set to 1 (or is a power of two) then msb and lsb should return the same position. Your main function asks the user to enter a positive non-zero integer and then outputs the distance between the first and last bits set to 1. For example, if the input is 9 (which is ....1001 in binary) then the output would be 3 because 3 - 0 is 3.

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!