0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ビット演算

0
Posted at
print('論理和')
print(0 | 0)
print(0 | 1)
print(1 | 0)
print(1 | 1)

print('論理積')
print(0 & 0)
print(0 & 1)
print(1 & 0)
print(1 & 1)

print('排他的論理和')
print(0 ^ 0)
print(0 ^ 1)
print(1 ^ 0)
print(1 ^ 1)

print('反転')
print(bin(0))
print(bin(~0))
print(bin(1))
print(bin(~1))

print('シフト')
print(bin(1 << 0))
print(bin(1 << 1))
print(bin(1 << 2))
print(bin(1 << 3))

実行結果:

論理和
0
1
1
1
論理積
0
0
0
1
排他的論理和
0
1
1
0
反転
0b0
-0b1
0b1
-0b10
シフト
0b1
0b10
0b100
0b1000
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?