1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// to-binary-bitops.cpp Print binary representation of ints // Fred Swartz - 2001-09-04 #include <iostream> using namespace std; int main() { int n; while (cin >> n) { cout << "decimal: " << n << endl; // print binary with leading zeros cout << "binary : "; for (int i=31; i>=0; i--) { int bit = ((n >> i) & 1); cout << bit; } cout << endl; }//end loop return 0; }//end main |
sizeof
.
string
class or a c-string (array of chars)?