// File binrep3.cpp shinnerl@ucla.edu 2/1/02 // Tests constness of "sizeof" expressions. const unsigned NDIGITS = sizeof(int)*8; // sizeof(int) is constant! #include #include using namespace std; int main(){ bool digits[ NDIGITS ]; cout << "Enter an int >= 0: "; int n; cin >> n; if (n < 0){ cout << "Input error! Negative data. " << endl; exit(-1); } int count = 0; do{ digits[count++] = n%2; n /= 2; }while ( n > 0 ); while (count-- > 0){ cout << digits[count]; } cout << endl; return 0; }