Bitwise-Operators - Ipynb - Colaboratory
Bitwise-Operators - Ipynb - Colaboratory
Bitwise-Operators - Ipynb - Colaboratory
ipynb - Colaboratory
1234
1234
1234
1234
0b1101
13
13
x = 0b11001011
y = 0b10101101
203
173
https://colab.research.google.com/drive/1HRmWEu_SRMH5C70IweNyWZSkI2hBZf97#printMode=true 1/6
24.06.2020 г. bitwise-operators.ipynb - Colaboratory
# bitwise AND -- use &
# if both of them are 1, we get 1
# x = 0b11001011
# y = 0b10101101
0b10001001
137
x & y
137
# bitwise OR -- use |
# if one of them is 1, then we get 1
# x = 0b11001011
# y = 0b10101101
0b11101111
239
x | y
239
# x = 0b11001011
# y = 0b10101101
0b01100110
https://colab.research.google.com/drive/1HRmWEu_SRMH5C70IweNyWZSkI2hBZf97#printMode=true 2/6
24.06.2020 г. bitwise-operators.ipynb - Colaboratory
102
x ^ y
102
first_choice = True
second_choice = False
third_choice = True
choices = 0b101
choices & 0b100 # mask -- only let the first_choice bit through, if it's there at all
def foo():
print("Hello")
bin(foo.__code__.co_flags)
https://colab.research.google.com/drive/1HRmWEu_SRMH5C70IweNyWZSkI2hBZf97#printMode=true 3/6
24.06.2020 г. bitwise-operators.ipynb - Colaboratory
bin(x)
~x
~1234
~-1234
bin(x)
bin(406)
https://colab.research.google.com/drive/1HRmWEu_SRMH5C70IweNyWZSkI2hBZf97#printMode=true 4/6
24.06.2020 г. bitwise-operators.ipynb - Colaboratory
bin(x)
0b110010110
bin(x)
0b110010110
x << 4
0b110010110000
3248
x >> 2
50
203
bin(x)
https://colab.research.google.com/drive/1HRmWEu_SRMH5C70IweNyWZSkI2hBZf97#printMode=true 5/6
24.06.2020 г. bitwise-operators.ipynb - Colaboratory
'0b11001011'
0b110010
50
https://colab.research.google.com/drive/1HRmWEu_SRMH5C70IweNyWZSkI2hBZf97#printMode=true 6/6