#include #include using namespace std; int main() { const int nbits {32}; //number of bits in an int on our machine const int n {2025}; //In binary, 00000000000000000000011111101001 const int bitmask {1}; //In binary, 00000000000000000000000000000001 //Output the bits of n, from most significant to least significant. //The & bitmask gives us a result in which only the rightmost bit of //shifted survives. for (int i {nbits - 1}; i >= 0; --i) { //loops 32 times const int shifted {n >> i}; const int theBit {shifted & bitmask}; //will be 1 or 0 cout << theBit; if (i > 0 && i % 8 == 0) { //the other kind of "and" cout << " "; //space for legibility } } cout << "\n"; return EXIT_SUCCESS; }