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

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!