how to solve this question?
Write a statement that assigns to x the value the bits 2, 3, and 4 of the integer y; x = _____________;
For example if y = 0x35 then the value of x after the execution of the statement will be 5;
Solution for the problem is provided below, please comment if any doubts:
Here the x value should be assigned with the values of the 2, 3, and 4th bits of the integer y.
To perform this task, first we need to extract the 2, 3, and 4th bits from y, this can be performed by using an AND operation with z, where z= ox1C = 00011100 (in binary)
Next, right shift the result by two bits right.
The statement is: SHIFT_RIGHT ((x AND ox1C), 2)
Note: since the format to be used is not provided, the exact key word may vary, but the logic is to be used is same.
Get Answers For Free
Most questions answered within 1 hours.