Advertisement
pan7nikt

Konwersja_szesnastkowy

Feb 12th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. using namespace std;
  5.  
  6. string str;
  7. bool dzielenie = true;
  8. int i;
  9. int l;
  10.  
  11. main()
  12. {
  13.     cout << "podaj liczbe dziesietna: ";
  14.     cin >> l;
  15.    
  16.     while(dzielenie)
  17.     {
  18.         if(l < 16)
  19.         {
  20.             dzielenie = false;
  21.         }
  22.        
  23.         //cout << l%2;
  24.         //stringstream ss;
  25.         //ss << l%2;
  26.         //string str = ss.str();
  27.         //str = to_string(l%2) + str;
  28.         switch(l%16)
  29.         {
  30.             case 0:
  31.             str = "0" + str; break;
  32.             case 1:
  33.             str = "1" + str; break;
  34.             case 2:
  35.             str = "2" + str; break;
  36.             case 3:
  37.             str = "3" + str; break;
  38.             case 4:
  39.             str = "4" + str; break;
  40.             case 5:
  41.             str = "5" + str; break;
  42.             case 6:
  43.             str = "6" + str; break;
  44.             case 7:
  45.             str = "7" + str; break;
  46.             case 8:
  47.             str = "8" + str; break;
  48.             case 9:
  49.             str = "9" + str; break;
  50.             case 10:
  51.             str = "A" + str; break;
  52.             case 11:
  53.             str = "B" + str; break;
  54.             case 12:
  55.             str = "C" + str; break;
  56.             case 13:
  57.             str = "D" + str; break;
  58.             case 14:
  59.             str = "E" + str; break;
  60.             case 15:
  61.             str = "F" + str; break;
  62.         }
  63.         l = l/16;
  64.     }
  65.    
  66.     cout << str;
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement