Last active
May 28, 2020 14:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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