-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13. Operator Bitwise.py
More file actions
74 lines (54 loc) · 1.91 KB
/
13. Operator Bitwise.py
File metadata and controls
74 lines (54 loc) · 1.91 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
# Episode OPERATOR BITWISE, OPERASI BINER, BINARY
a = 9
b = 5
# Bitwise OR (|)
c = a | b
print("\n======OR======")
print("Nilai = ", a,",binernya = ", format(a,"08b"))
print("Nilai = ", b,",binernya = ", format(b,"08b"))
print("=================================(|)")
print("Nilai = ", c,",binernya = ", format(c,"08b"))
# Bitwise AND (&)
c = a & b
print("\n======AND======")
print("Nilai = ", a,",binernya = ", format(a,"08b"))
print("Nilai = ", b,",binernya = ", format(b,"08b"))
print("=================================(&)")
print("Nilai = ", c,",binernya = ", format(c,"08b"))
# Bitwise XOR (&)
c = a ^ b
print("\n======XOR======")
print("Nilai = ", a,",binernya = ", format(a,"08b"))
print("Nilai = ", b,",binernya = ", format(b,"08b"))
print("=================================(^)")
print("Nilai = ", c,",binernya = ", format(c,"08b"))
# Bitwise XOR (&)
c = a ^ b
print("\n======XOR======")
print("Nilai = ", a,",binernya = ", format(a,"08b"))
print("Nilai = ", b,",binernya = ", format(b,"08b"))
print("=================================(^)")
print("Nilai = ", c,",binernya = ", format(c,"08b"))
# Bitwise NOT (~)
c = ~a
print("\n======NOT======")
print("Nilai = ", a,", Binernya = ", format(a,"08b"))
print("--------------------------(~)")
print("Nilai = ", c,", Binernya = ", format(c,"08b"))
print("--------------------------(^)")
d = 0b0000001001
e = 0b1111111111
print("Nilai = ", e^d,", Binernya = ", format(e^d, "08b"))
# SHIFT
# SHIFT RIGHT (>>)
c = a >> 2
print("\n==========>>=========")
print("Nilai = ", a,", Binernya = ", format(a,"08b"))
print("--------------------------(>>)")
print("Nilai = ", c,", Binernya = ", format(c,"08b"))
# SHIFT LEFT (<<)
c = a << 2
print("\n==========<<=========")
print("Nilai = ", a,", Binernya = ", format(a,"08b"))
print("--------------------------(<<)")
print("Nilai = ", c,", Binernya = ", format(c,"08b"))