06-23-2014, 08:50 PM
Determining if number is power of 2 (excluding 0)
Parity of a byte
Modulus by 1 << s:
Code:
f = (v & (v - 1)) == 0
Parity of a byte
Code:
bool parity =
(((b * 0x0101010101010101ULL) & 0x8040201008040201ULL) % 0x1FF) & 1;
Modulus by 1 << s:
Code:
m = n & ((1<< s) - 1);