Question
(C programming) Write a function, getMask that takes three integers as parameters and returns a single integer. The first two parameters are the start and
(C programming) Write a function, getMask that takes three integers as parameters and returns a single integer. The first two parameters are the start and end bit position. The third parameter should be passed either a 0 or 1 to determine the type of mask.
The function should create an integer and set the bits specified in the first two parameters to the value in the third parameter. All other bits in the integer should be set to the opposite value of the third parameter. The function should return that integer mask.
For example, getMask(2, 6, 1); Set bits 2 to 6 to 1, set all others to zero should set the bits 2 through 6 to a 1 and all other bits to zero. This should return integer 124.
If the argument in the third parameter is anything other than 0 or 1, return 0. If the start bit position is greater than the end bit position, return 0. If the start bit position or the end bit position is greater than 31 or less than 0, return 0.
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