Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
45 lines (40 loc) · 1.25 KB

File metadata and controls

45 lines (40 loc) · 1.25 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.