Skip to content

Instantly share code, notes, and snippets.

@Ch-sriram
Last active May 28, 2020 14:22
Show Gist options
  • Save Ch-sriram/fef3d0a6274d20f6705495b7cf5b22e4 to your computer and use it in GitHub Desktop.
Save Ch-sriram/fef3d0a6274d20f6705495b7cf5b22e4 to your computer and use it in GitHub Desktop.
Given a number N & a bit position - i, WAF to check whether the i'th bit is set in N or not.
bool checkith (int N, int i) {
return N & (1 << i);
// Other solutions are:
// return (N >> i) % 2;
// return (N >> i) & 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment