#include #include #include using namespace std; int main() { //Each octal digit is an abbreviation for a series of three bits. //There are 8 possible octal digits. const string a[] { "0", //0000 "1", //0001 "2", //0010 "3", //0001 "4", //0100 "5", //0101 "6", //0110 "7", //0111 }; const int nbits {32}; //number of bits in an int on our machine const int n {2025}; //In binary, 00000000000000000000011111101001 const int bitmask {7}; //In binary, 00000000000000000000000000000111 //Output the bits of n as 11 octal digits. //The & bitmask gives us a result in which only the rightmost 3 bits of //shifted survive. for (int i {nbits - 2}; i >= 0; i -= 3) { //loops 11 times const int shifted {n >> i}; const int theBits {shifted & bitmask}; cout << a[theBits]; //thebits is in the range 0 to 7 inclusive. } cout << "\n"; return EXIT_SUCCESS; }