Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
mkl
on Sept 9, 2019
|
parent
|
context
|
favorite
| on:
Popcount CPU instruction
Isn't that what the "x &&" is for? For x = 0, (x - 1) is 0xffffffff, x & (x-1) is 0, !(x & (x-1)) is 1, and x && !(x & (x-1)) is 0.
tromp
on Sept 9, 2019
[–]
Yes, that's exactly what it's for. The answer I hope for is that they don't care about the case of x==0, so that I can leave out the "x &&" part, leaving the noticeably simpler answer
(x & x-1) == 0
Consider applying for YC's W25 batch! Applications are open till Nov 12.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: