8000 Operators example · dsabhrawal/python-examples@bb05a7c · GitHub
[go: up one dir, main page]

Skip to content

Commit bb05a7c

Browse files
committed
Operators example
1 parent 3f3125c commit bb05a7c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Operators/BitwiseOperator.py

Lines changed: 38 additions & 0 deletions
28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# & (AND), | (OR), ~ (Compliment), ^ (XOR), << (Left Shift) , >> (Right Shift)
2+
#Bitwise operators only works on int in binary form
3+
4+
# AND (&) Table
5+
# 1 & 1 = 1
6+
# 1 & 0 = 0
7+
# 0 & 1 = 0
8+
# 0 & 0 = 0
9+
10+
# OR (|) Table
11+
# 1 & 1 = 1
12+
# 1 & 0 = 1
13+
# 0 & 1 = 1
14+
# 0 & 0 = 0
15+
16+
# XOR (^) Table
17+
# 1 & 1 = 0
18+
# 1 & 0 = 1
19+
# 0 & 1 = 1
20+
# 0 & 0 = 0
21+
22+
# Compliment (~)
23+
# ~1 = 0
24+
# ~0 = 1
25+
26+
print(7 & 19) #3
27+
print(7 | 19) #23
+
print(~7)
29+
30+
print(bin(3)) #0b11
31+
print(bin(7)) # 0b111
32+
print(bin(19)) # 0b10011
33+
print(bin(23)) #0b10111
34+
35+
36+
37+
38+

0 commit comments

Comments
 (0)
0