Skip to content

Commit a70bbc8

Browse files
author
CodexRitik
committed
Bitwise Operators In Java.
1 parent 4178aaa commit a70bbc8

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/BitwiseOperators.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)