/* File binrep0.cpp Version 0: display digits IN REVERSE ORDER. This program prints out from right to left the binary digits of an integer entered by the user at run time. Because the digits are acquired by integer division using %, they are easily displayed "backwards," i.e., from right to left. (See the sample I/O at the end of this file for examples.) J. Shinnerl, 10/18/99; 10/18/01 */ #include using std::cout; using std::cin; using std::endl; int main() { cout << "\nThis program prints out the binary digits of an integer " << "in reverse order."; cout << "\nEnter an integer (max. abs. value 1,000,000,000): "; int number; cin >> number; do { // Acquire the digits from right to cout << number%2; // left and display them immediately, number = number / 2; // reversing the order. }while ( number > 0 ); cout << endl << endl; return 0; } /* SAMPLE I/0: barcarolle.cs.ucla.edu.92> a.out This program prints out the binary digits of an integer in reverse order. Enter an integer (max. abs. value 1,000,000,000): 4 001 barcarolle.cs.ucla.edu.93> a.out This program prints out the binary digits of an integer in reverse order. Enter an integer (max. abs. value 1,000,000,000): 6 011 barcarolle.cs.ucla.edu.94> a.out This program prints out the binary digits of an integer in reverse order. Enter an integer (max. abs. value 1,000,000,000): 35 110001 barcarolle.cs.ucla.edu.95> */