1- The AND operator : (&)
Code:
x? ? ? ? ? ?y? ? ? ? ? ? ? ? ?x&y?
-----------------------------
0? ? ? ? ? ?0? ? ? ? ? ? ? ? ? 0
0? ? ? ? ? ?1? ? ? ? ? ? ? ? ? 0
1? ? ? ? ? ?0? ? ? ? ? ? ? ? ? 0
1? ? ? ? ? ?1? ? ? ? ? ? ? ? ? 1
Example on & operator Code:
? ? ?byte x = 50;
? ? ?byte y = 51;
? ? ?byte result = (byte) (x&y);
? ? System.out.println("Result of x&y= : " + result );
The result equal = 5000110010
00110011
-------------
00110010
2- The OR operator : (|)
Code:
x? ? ? ? ? ?y? ? ? ? ? ? ? ? ?x|y?
-----------------------------
0? ? ? ? ? ?0? ? ? ? ? ? ? ? ? 0
0? ? ? ? ? ?1? ? ? ? ? ? ? ? ? 1
1? ? ? ? ? ?0? ? ? ? ? ? ? ? ? 1
1? ? ? ? ? ?1? ? ? ? ? ? ? ? ? 1
Example on | operator Code:
? ? ?byte x = 50;
? ? ?byte y = 51;
? ? ?byte result = (byte) (x|y);
? ? System.out.println("Result of x|y= : " + result );
The result equal = 5100110010
00110011
-------------
00110011
3- The XOR operator : (^)
Code:
x? ? ? ? ? ?y? ? ? ? ? ? ? ? ?x^y?
-----------------------------
0? ? ? ? ? ?0? ? ? ? ? ? ? ? ? 0
0? ? ? ? ? ?1? ? ? ? ? ? ? ? ? 1
1? ? ? ? ? ?0? ? ? ? ? ? ? ? ? 1
1? ? ? ? ? ?1? ? ? ? ? ? ? ? ? 0
Example on ^ operator Code:
? ? ?byte x = 50;
? ? ?byte y = 51;
? ? ?byte result = (byte) (x^y);
? ? System.out.println("Result of x^y= : " + result );
The result equal = 100110010
00110011
-------------
00000001
4- The Inversion Operator: (~)
Invert each bit in the byte .
Example :
Code:
~00110010 = 11001101
5- Boolean Inversion Operator (!)
invert the value of boolean