-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitLogic.java
More file actions
32 lines (26 loc) · 1003 Bytes
/
Copy pathBitLogic.java
File metadata and controls
32 lines (26 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Demonstrate bitwise logical operators
public class BitLogic {
public static void main(String args[]){
String binary[] = {
"0000","0001","0010","0011","0100","0101","0110","0111",
"1000","1001","1010","1011","1100","1101","1110","1111"
};
int a = 3; // 0 + 2 + 1 or 0011 in binary
int b = 6; // 4 + 2 + 0 or 0110 in binary
int c = a | b;
int d = a & b;
int e = a ^ b;
int f = (~a ^ b) | (a & ~b);
int g = ~a ;
System.out.println(" a = " + binary[a]);
System.out.println(" b = " + binary[b]);
System.out.println(" a|b = " + binary[c]);
System.out.println(" a&b = " + binary[d]);
System.out.println(" a^b = " + binary[e]);
System.out.println("(~a ^ b) | (a & ~b) = " + binary[f]);
System.out.println(" ~a = " + binary[g] );
}
}
/*
output
*/