-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitwiseoperator.java
More file actions
73 lines (64 loc) · 1.6 KB
/
Bitwiseoperator.java
File metadata and controls
73 lines (64 loc) · 1.6 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package basics;
public class Bitwiseoperator {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Btwise And operator:");
System.out.println(5&1);
/*
* 5-> 0101
* 1-> 0001
* 5&1->0001
* 0001->1
*/
System.out.println("Btwise or operator:");
System.out.println(5|1);
/*
* 5-> 0101
* 1-> 0001
* 5&1->0101
* 0001->5
*/
System.out.println("Btwise Not operator:");
System.out.println(~5);
/*
* 5-> 0101
* ~5-> 1010
* 1010->10(32 bit operation -> -6)
* 5->00000000000000000000000000000101
* ~5->11111111111111111111111111111010->-6
*/
System.out.println("Btwise XOR operator:");
System.out.println(5^1);
/*
* 5-> 0101
* 1-> 0001
* 5&1->0100
* 0100->4
*/
System.out.println("Btwise Zero fill Left shift operator:");
System.out.println(9<<1);
/*
* 9-> 1001
* 9<<1->0010 remove leftmost bit(0) add 0 to right most end
* 0001->2
*/
System.out.println("Btwise signed Right shift operator:");
System.out.println(9>>1);
/*
* 9-> 1001
* 1-> 0001
* 9>>1->1100 remove right most bit i.e 1 add left most side by copies of last left most bit i.e 1
* 1100->12(not written 12) in java it is do 32 bit operation
* 00000000000000000000000000001001>>00000000000000000000000000000001
* 00000000000000000000000000000100->4
*/
System.out.println("Btwise Zero fill right shift operator:");
System.out.println(9>>>1);
/*
* 9-> 1001
* 1-> 0001
* 9>>>1->0100
* 0100->4
*/
}
}