4 ms·
"b += 15 * (b & 0x00000000ffffffffULL)" might look more magical than it actually is. The crux is: b * 4 is the same as b << 2 thus b += 3 * b
by gorset 15y ago
"b += 15 * (b & 0x00000000ffffffffULL)" might look more magical than it actually is. The crux is:
b * 4
is the same as
b << 2
thus
b += 3 * b
is the same as
b = b << 2
So plus, a multiply and a mask make it possible to shift only a subset of the bits in the integer. The first transformation uses two masks and bitwise or to achieve the same.