57
60

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 2012-12-26

色々使いどころがありそうなのにあんまりみかけないので、ベストプラクティス的な使い方やおもしろい使い方があれば教えてください。

自分はテストのパターンを作成するときに使いました。3つのフラグのtrue/falseについて、漏れダブりなくテストケースを生成するために次のようなコードを書きました。

first = 1
second = 2
third = 4
cases = (make_case(i & first,i & second,i & third) for i in [0..7])
57
60
9

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
57
60

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?