-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitOperations.java
More file actions
45 lines (40 loc) · 1.25 KB
/
BitOperations.java
File metadata and controls
45 lines (40 loc) · 1.25 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
package Bit_Manipulation;
class BitOperations{
public static void main(String[] args){
int a=15; //0000 1111
int b=21; //0001 0101
//AND Operation
/*
0000 1111
& 0001 0101
--------------
0000 0101
*/
int f=(a&(a-1));
System.out.println("Power of 2 Operation : "+f+" Binary value: "+Integer.toBinaryString(f));
int and=a&b;
System.out.println("AND Operation : "+and+" Binary value: "+Integer.toBinaryString(and));
//OR Operation
/*
0000 1111
| 0001 0101
--------------
0001 1111
*/
int or=a|b;
System.out.println("OR Operation : "+or+" Binary value: "+Integer.toBinaryString(or));
//XOR Operation
/*
0000 1111
& 0001 0101
--------------
0001 1010
*/
int xor=a^b;
System.out.println("XOR Operation : "+xor+" Binary value: "+Integer.toBinaryString(xor));
int x=7;
//NOT Operation
int not=~x;
System.out.println("NOT Operation : "+not+" Binary value: "+Integer.toBinaryString(not));
}
}