-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitLogic.java
More file actions
25 lines (23 loc) · 840 Bytes
/
BitLogic.java
File metadata and controls
25 lines (23 loc) · 840 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
//Demonstrate the bitwise logical operater.
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 binary 0011
int b = 6; //4 + 2 + 0 or binary 0110
int c = a | b;
int d = a & b;
int e = a ^ b;
int f = (~a & b) | (a & ~b);
int g = ~a & 0x0f;
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]);
}
}