|
|
|
|
|
by hairtuq
1291 days ago
|
|
On a related note, almost any task around shuffling or shifting bits can be improved with xor. For example the straightforward way to remove bit i is mask = -1 << i;
return (x & ~mask) | ((x >> 1) & mask);
but with xor we can do it in one less instruction: mask = -1 << i;
return ((x ^ (x >> 1)) & mask) ^ x;
|
|