Skip to content

Instantly share code, notes, and snippets.

@Nan-Zhang
Last active August 29, 2015 14:06
Show Gist options
  • Save Nan-Zhang/566bc1d0ec200c13935d to your computer and use it in GitHub Desktop.
Save Nan-Zhang/566bc1d0ec200c13935d to your computer and use it in GitHub Desktop.
show ith of a: a & 1 << i
reset ith of a: a &= ~(1 << i)
populate the result: result |= 1 << i
(-i) & i; //NOTE from right to left, get first '1' and other bits is '0'
n & (n - 1) == 0 check if n is power of 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment