-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbitwise.py
56 lines (47 loc) · 1.53 KB
/
bitwise.py
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
# episode operator bitwise, operasi biner, binary
a = 9
b = 5
# bitwise OR (|)
c = a | b
print('\n=========OR=========')
print('nilai :',a,' , binary :',format(a,'08b'))
print('nilai :',b,' , binary :',format(b,'08b'))
print('----------------------------- (|)')
print('nilai :',c,' , binary :',format(c,'08b'))
# bitwise AND (&)
c = a & b
print('\n=========AND========')
print('nilai :',a,' , binary :',format(a,'08b'))
print('nilai :',b,' , binary :',format(b,'08b'))
print('----------------------------- (&)')
print('nilai :',c,' , binary :',format(c,'08b'))
# bitwise XOR (^)
c = a ^ b
print('\n=========XOR========')
print('nilai :',a,' , binary :',format(a,'08b'))
print('nilai :',b,' , binary :',format(b,'08b'))
print('----------------------------- (^)')
print('nilai :',c,' , binary :',format(c,'08b'))
# bitwise NOT (~)
c = ~a
print('\n=========NOT========')
print('nilai :',a,' , binary :',format(a,'08b'))
print('----------------------------- (~)')
print('nilai :',c,' , binary :',format(c,'08b'))
print('----------------------------- (^)')
d = 0b0000001001
e = 0b1111111111
print('nilai :',e^d,' , binary :',format(e^d,'08b'))
# shifting
# shift right (>>)
c = a >> 2
print('\n=========>>=========')
print('nilai :',a,' , binary :',format(a,'08b'))
print('----------------------------- (>>)')
print('nilai :',c,' , binary :',format(c,'08b'))
# shift left (<<)
c = a << 2
print('\n=========<<=========')
print('nilai :',a,' , binary :',format(a,'08b'))
print('----------------------------- (<<)')
print('nilai :',c,' , binary :',format(c,'08b'))