Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Test(int *p, int x)
  6. {
  7.     for (int i = 0; i <16; i++)
  8.     {
  9.         if(x&(1<<i))
  10.         p[i] = 1;
  11.         else
  12.          p[i] = 0;
  13.  
  14.     }
  15. }
  16.  
  17. void write(int *p)
  18. {
  19.     for (int i = 15; i  >=0; i--)
  20.     {
  21.         cout << p[i];
  22.     }
  23. }
  24.  
  25.  
  26.  
  27.  
  28. int main()
  29. {
  30.     int * p = new int[16];
  31.  
  32.     cout << "Zadejte dekadicke cislo: ";
  33.     short int x;
  34.     cin >>x;
  35.     Test(p,  x);
  36.  
  37.     cout << "Binarne: ",
  38.     write(p);
  39.     cout << endl;
  40.     cout << "Hexadecimalne: " << hex << x << endl;
  41.     cout << "Dekadicky (unsigned): " << dec << (unsigned short int) x << endl;
  42.     cout << "Dekadicky (int): "  << dec <<x;
  43.  
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement