In: Computer Science
Suppose x = 0x5A and y = 0xA5.
What is the output for x | y?
What is the output for x & y?
What is x for x = ~y?
What is the output for x ^ y?
Please up vote ,comment if any query . Thanks for question . be safe .
Result :
Answer : x | y = 0xFF
| bitwise -OR operator
0x5A | 0xA5
In binary : 0x5A = 0101 1010 , 0xA5= 1010 0101
0101 1010
OR 1010 0101
---------------------------
1111 1111 = 0xFF
What is bit-wise OR when
0 | 0 = 0
1 | 0 =1
0 | 1 = 1
1 | 1 = 1
Answer : x & y = 0x5A & 0xA5 =0x00
& bitwise AND operator
bitwise AND
0 & 0 = 0
1 & 0 = 0
0 & 1 = 0
1 & 1 = 1
x & y = 0x5A & 0xA5
in binary :
0101 1010
& 1010 0101
--------------------------------------
0000 0000 = 0x00
Answer : x = ~y x= ~0xA5 , x=0x5A
~ NOT operator
~1 = 0
~0 = 1
NOT operator inverse the bits when bit is 0 than inverse will be 1 ,when bit is 1 inverse will be 0
~1010 0101 = 0101 1010 = 0x5A
Answer : x^y = 0x5A ^ 0xA5 = 0xFF
^ Ex-OR operator
when both operand bit same result will be zero else will be 1.
0 ^ 0 = 0
1 ^ 0 = 1
0 ^ 1 = 1
1 ^ 1 = 0
0x5A ^ 0xA5
0101 1010
^ 1010 0101
-----------------------------------------------
1111 1111 = 0xFF
Answer = 0xFF
Please up vote ,comment if any query .