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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started