Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the function clear Bits which takes two arguments: data, and d. Clear

ID: 3863603 • Letter: I

Question

Implement the function clear Bits which takes two arguments: data, and d. Clear Bits should zero out the most significant (leftmost) b bits of the (possibly signed) char data, leaving the other bits unchanged and then return this value. For example, if the binary representation of data is 11011011 and b is 3, clear Bits should return the number whose binary representation is 00011011. Another example is if the binary representation of data is 11011001 and b is 6, clear Bits should return the number whose binary representation is 00000031. You may assume that the value of b is always in the range 0 and 8 (including both 0 and 8). char clear Bits (char data, int b) {//Create a bitmask that has 0s where we want to clear//and Is where we want to preserve. unsigned char mask - [BLANK A]//Combine data and the bitmask return data [BLANK BJ mask;

Explanation / Answer

char clearBits(char data[],int b)
{
unsigned char mask=data.shiftRight(b);
return data&mask;
}

Example 1:-

data 11011011 ,b=3

unsigned char mask will be = 00011111

data&mask;

00011111

11011011

-----------------

00011011

Example 2:-

Data= 11011001, b=6

unsigned char mask will be = 00011111

data&mask;

00000011

11011001

-----------------

00000001

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.