7
4

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.

ビットクリア演算子(&^)

Last updated at Posted at 2016-07-31

Go にはビットクリア演算子(&^)というのがある。

x y x &^ y
0 0 0
0 1 0
1 0 1
1 1 0

結果に対し x と y が対称ではないしなんだこれ?と思ったけど、大した話ではなく x の 0 にしたいビットを y で指定してるだけですね。例えば x の下位 2 ビットをクリアするのであれば y の下位 2 ビットを 1 にする。

x 0101
y 0011
x &^ y 0100

ってことですね。

7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?