Advertisement
idsystems

CPP_Practica58_DecimalAHexadecimal

Mar 13th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. // Program: hexa.cc
  2. // Author:  Yoan Pinzon
  3. // Date:    Agosto 30, 2006
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.    int n;
  12.    while (cin >> n)
  13.    {
  14.       cout << "decimal: " << n << endl;
  15.  
  16.       // print hex with leading zeros
  17.       cout << "hex : ";
  18.       for (int i=2*sizeof(int) - 1; i>=0; i--)
  19.       {
  20.          cout << "0123456789ABCDEF"[((n >> i*4) & 0xF)];
  21.       }
  22.       cout << endl << endl;
  23.    }
  24.  
  25.    return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement