Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

boolean checkExactlyOneBitSet(int num) {

return (num & (num - 1)) == 0;

}

That looks like it'll fail when num == 0. I think it should be:

  return num && ((num & (num - 1)) == 0);


maybe posting a github issue would be helpful




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: