File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Bitwise operator works on bits and performs
3+ bit-by-bit operation.
4+ 1.& (bitwise and)
5+ 2.| (bitwise or)
6+ 3.^ (bitwise XOR)
7+ 4.~ (bitwise compliment)
8+ 5.<< (left shift)
9+ 6.>> (right shift)
10+ 7.>>> (zero fill right shift)
11+ */
12+ public class BitwiseOperators {
13+ public static void main (String [] args ) {
14+ int a = 60 ; /* 60 = 0011 1100 */
15+ int b = 13 ; /* 13 = 0000 1101 */
16+ int c = 0 ;
17+ c = a & b ; /* 12 = 0000 1100 */
18+ System .out .println ("a & b = " + c );
19+ c = a | b ; /* 61 = 0011 1101 */
20+ System .out .println ("a | b = " + c );
21+ c = a ^ b ; /* 49 = 0011 0001 */
22+ System .out .println ("a ^ b = " + c );
23+ c = ~a ; /*-61 = 1100 0011 */
24+ System .out .println ("~a = " + c );
25+ c = a << 2 ; /* 240 = 1111 0000 */
26+ System .out .println ("a << 2 = " + c );
27+ c = a >> 2 ; /* 15 = 1111 */
28+ System .out .println ("a >> 2 = " + c );
29+ c = a >>> 2 ; /* 15 = 0000 1111 */
30+ System .out .println ("a >>> 2 = " + c );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments