-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperatorBitwise.java
More file actions
77 lines (65 loc) · 1.58 KB
/
Copy pathOperatorBitwise.java
File metadata and controls
77 lines (65 loc) · 1.58 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
74
75
76
77
public class OperatorBitwise {
public static void main(String[] args) {
// bitwise and -> &
// bitwise or -> |
// bitwise xor -> ^
// bitwise not -> ~
// shiffting kiri -> <<
// shiffting kanan -> >>
// shiffting kanan (unsigned) -> >>>
// 0 & 0 -> 0
// 1 & 0 / 0 & 1 -> 0
// 1 & 1 -> 1
// int hasilAnd = 5 & 3;
// 5 = 0101
// 3 = 0011
// and = 0001 -> 1
// System.out.println(hasilAnd);
// 0 | 1 -> 1 terkecuali 0 | 0 -> 0
// 1 | 1 -> 1
// int hasilOr = 5 | 3;
// 5 = 0101
// 3 = 0011
// or = 0111 -> 7
// System.out.println(hasilOr);
// 0 ^ 0 -> 0
// 0 ^ 1 -> 1
// 1 ^ 0 -> 1
// 1 ^ 1 -> 0
// int hasilXor = 5 ^ 3;
// 5 = 0101
// 3 = 0011
// xor = 0110 -> 6
// System.out.println(hasilXor);
// 0 -> ~ -> 1
// 1 -> ~ -> 0
// 0101 -> ~ -> 1010
// angka = 5;
// ~angka
// 0000000 000000 0000000 000000101
// 1111111 111111 1111111 111111010
// int hasilComplement = ~5;
// System.out.println(hasilComplement);
// ~nilai = -(nilai + 1)
// ~20 = -(20 + 1) = -21
// 5 << 1;
// 00001010
// int hasilShiftingKiri = 5 << 1;
// System.out.println(hasilShiftingKiri);
// nilai << n;
// nilai x 2^n
// 5 << 2;
// 5 x 2 ^ 2
// 20
// 20
// 00010100
// 20 >> 1
// int hasilShiftingKanan = 20 >> 1;
// System.out.println(hasilShiftingKanan);
int a = 20;
int x = a >> 1;
int y = a >>> 1;
System.out.println(x);
System.out.println(y);
}
}