There are a number of ways to implement your arithmetic test using bitwise arithmetic. Your expression:
x == 0 || x == 1
is logically equivalent to each one of these:
(x & 1) == x(x & ~1) == 0(x | 1) == 1(~x | 1) == (uint)-1x >> 1 == 0
Bonus:
x * x == x(the proof takes a bit of effort)
But practically speaking, these forms are the most readable, and the tiny difference in performance isn’t really worth using bitwise arithmetic:
x == 0 || x == 1x <= 1(becausexis an unsigned integer)x < 2(becausexis an unsigned integer)