4 ms·
A neat trick for clearing the lowest bit is subtracting one and and'ing that with the original: x_cleared = x & (x - 1); You can get the lowest bit from t
by barrkel 16y ago
A neat trick for clearing the lowest bit is subtracting one and and'ing that with the original:
x_cleared = x & (x - 1);
You can get the lowest bit from the difference.
- bnoordhuis 16y agoIsn't this easier and faster, both type- and performance-wise? x_cleared = x & ~1;
- jonsen 16y agoThe intension is to clear the rightmost 1-bit.
- arethuza 16y agoI'm pretty sure that doesn't do what I was asked to do.