Created
October 7, 2019 02:01
-
-
Save sajith/7a2c551015e302e127690f378398ea74 to your computer and use it in GitHub Desktop.
Check if a bit is set
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
#include <iostream> | |
bool test_bit_set(unsigned num, unsigned idx) | |
{ | |
return (num & (1 << idx)) != 0; | |
} | |
int main() | |
{ | |
for (unsigned n = 0; n < 8; n++) | |
{ | |
for (unsigned i = 0 ; i < 8; i++) | |
{ | |
std::cout << i << "th bit of " << n << " set : " | |
<< (test_bit_set(n, i) ? "true" : "false") << "\n"; | |
} | |
std::cout << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment