In: Computer Science
What is the effect of applying ^255 to a 16-bit number?
^ is the bitwise XOR operation.
It inverts the low byte and leaves the high byte unchanged.
It inverts the high byte and leaves the low byte unchanged.
Suppose x is an 8-bit number and y is a 3-bit number. What is the effect of the following assignment?
x = (x & 248) + y
& is the bitwise AND operator.
If x was originally 248, then x is now y+1, otherwise, it is y.
x is 248 + y after the assignment.
The lower 5 bits of x are unchanged, the number represented by the upper 3 bits is changed to y.
The upper 5 bits of x are unchanged, the number represented by the lower 3 bits is changed to y.
SOL:
1) The correct answer is It inverts the low byte and leaves the high byte unchanged.
Explanation:
Given ^ is the bitwise XOR operation
255 Binary equivalent in 16 bit = 0000000011111111
Now take another 16 bit number =101010101010101010
Now we perform the Bitwise XOR operation of above two numbers
0000000011111111
1010101010101010
_________________
1010101001010101 ---> result
Now we are seeing in the result that First 8 bits which is called low byte gets inverted and high byte(last8 bits) remains unchanged
whatever 16 bit number we take we will get the same result
2) Given X is a 8 bit number and Y is a 3 bit number
X=(X&248)+Y
The correct answer is
The upper 5 bits of x are unchanged, the number represented by the lower 3 bits is changed to y.
Explanation:
Given X is of 8 bits so take X=10101010
Y is of 3 bits so take Y = 111
Now 248 binary equivalent is 11111000
Niw performing (X&248)
X = 10101010
248=11111000
_______________
X&248 = 10101000 ---> result
Now adding Y 111 to the result
10101000
+ 111
__________
10101111 ---> final result
so X= 10101111
Original X= 10101010
see in the final X compared to original X upper 5 bits remaining unchanged and lower 3 bits is changed to Y
whatever the X and Y value we take we will get the same result