Question: 2. [15 points] Bitwise and shift operations (a) [4 points] Suppose that x and y have byte values Ox5a and 0x73 respectively. Fill in the

 2. [15 points] Bitwise and shift operations (a) [4 points] Suppose

that x and y have byte values Ox5a and 0x73 respectively. Fill

2. [15 points] Bitwise and shift operations (a) [4 points] Suppose that x and y have byte values Ox5a and 0x73 respectively. Fill in the following table indicating the byte values of the different expressions: Expression Value Expression Value x & y X && y xy x 11 Y xy !x || !y x & !y x && "Y (b) [3 points] Fill in the following table showing the effects of the different shift operators on single-byte quantities. Each of the answers should be 8 binary digits or 2 hexadecimal digits. Note that the third column is a logical right shift operator, while the rightmost column is an arithmetic right shift operator. x > 3 (Arithmetic) x >> 3 Hex Binary Binary Hex Binary Hex Binary Hex Ox5d Oxb3 - - - - -- - -- -- Oxa9 - -- (c) [8 points] For the next two problems, assume that x is an 32-bit int. For reference, we will begin counting bits and nibbles of x from the least significant bit, so the most significant bit is the 32nd bit and the most significant nibble is the 8th nibble. i. [4 points] Give a C expression that will return the 5th nibble of x as a char using only bit-level operators, shifts operators, and 1-byte constants. As an example, if x = 0x12345678 then the expression should return 0x04. ii. [4 points] Give a C expression that will set the 18th and 20th bits of x to 1, leaving everything else unchanged using only bit-level operators, shift operators, and 1-byte constants? As an example, if x = 0x12345678 then the expression should set the value of x to Ox123e5678

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!