what is the difference between bitwise AND (&) and bitwise OR (|) in Java?
Answers
Answered by
6
Bitwise operators in Java are:
AND: & :
When we want to AND bitwise the two operands or integers (of same size) we use this operator. Suppose A = 25. or 0x19. Let B = 0x14 = 20.
A & B = 0001 1001 & 0001 0100 = 0001 0000 = 16
nth bit of A is ANDed with bit n of B.
1 & 1 = 1 ; 1 & 0 = 0 ; 0 & 1 = 0 ; 0 & 0 = 0.
OR : |
When we want bitwise OR of two operands or integers we use this operator. The bit 1 of A is ORed with bit 1 of B. Bit n of A is ORed with bit n of B.
A | B = 0001 1101 = 29
1 | 1 = 1 ; 1 | 0 = 1 ; 0 | 1 = 1; 0 | 0 = 0.
AND: & :
When we want to AND bitwise the two operands or integers (of same size) we use this operator. Suppose A = 25. or 0x19. Let B = 0x14 = 20.
A & B = 0001 1001 & 0001 0100 = 0001 0000 = 16
nth bit of A is ANDed with bit n of B.
1 & 1 = 1 ; 1 & 0 = 0 ; 0 & 1 = 0 ; 0 & 0 = 0.
OR : |
When we want bitwise OR of two operands or integers we use this operator. The bit 1 of A is ORed with bit 1 of B. Bit n of A is ORed with bit n of B.
A | B = 0001 1101 = 29
1 | 1 = 1 ; 1 | 0 = 1 ; 0 | 1 = 1; 0 | 0 = 0.
kvnmurty:
:-)
Similar questions