Question: Build a method in C that will return an int, take 3 ints as parameters. The first and second int are the starting and ending
Build a method in C that will return an int, take 3 ints as parameters. The first and second int are the starting and ending bit position. The third int is a 0 or 1 to determine the type of mask.

This is what I have:
int getM(int start, int end, int choice) { int blank1 = 0; int blank2 = 2147483647; int length = end - start + 1; if (choice == 1){ while(length > 0) { blank1++; blank1 0){ blank2--; blank2
}
but its returning 5 for getM(2, 6, 1).
Thank you!
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. 31 30 29 28 27 26 25 24 23 22 21 20 19 18 1716 15 14 13 12 111098765 4 32 1 0 So getMask(2,6,13) should return the integer 124. And getMask(11, 31, 0) (set bits 11 to 31 to 0) should return 2047 31 30 29 28 27 26 25 24 23 22 21 20 19 18 1716 15 14 13 12 111098765 4 32 1 0 0 0 0 11 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
