CosminVarlan

BitsExamples

Mar 9th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     unsigned int x = 75;
  8.     unsigned int y = 19;
  9. //    for(int i=0; i<32; i++)
  10. //        cout << "bitul "<< i << ':' << ((1<<i)&x ? '1' : '0') << '\n';
  11.  
  12.     for(int i=31; i>=0; i--)
  13.         cout << ((1<<i)&x ? '1' : '0');
  14.     cout <<" x";
  15.  
  16.     cout << '\n';
  17.  
  18.     for(int i=31; i>=0; i--)
  19.         cout << ((1<<i)&y ? '1' : '0');
  20.     cout <<" y";
  21.  
  22.     unsigned int si = x & y;
  23.     cout << '\n';
  24.     for(int i=31; i>=0; i--)
  25.         cout << ((1<<i)&si ? '1' : '0');
  26.     cout <<" x&y";
  27.  
  28.     unsigned int sau = x | y;
  29.     cout << '\n';
  30.     for(int i=31; i>=0; i--)
  31.         cout << ((1<<i)&sau ? '1' : '0');
  32.     cout <<" x|y";
  33.  
  34.     unsigned int notx = ~x;
  35.     cout << '\n';
  36.     for(int i=31; i>=0; i--)
  37.         cout << ((1<<i)&notx ? '1' : '0');
  38.     cout <<" ~x";
  39.  
  40.  
  41.     unsigned int xshstg3 = x << 3;
  42.     cout << '\n';
  43.     for(int i=31; i>=0; i--)
  44.         cout << ((1<<i)&xshstg3 ? '1' : '0');
  45.     cout <<" x<<3" << " adica " << xshstg3;
  46.  
  47.     unsigned int shdr3 = 64 >> 3;
  48.     cout << '\n';
  49.     for(int i=31; i>=0; i--)
  50.         cout << ((1<<i)&shdr3 ? '1' : '0');
  51.     cout <<" 64>>3" << " adica " << shdr3;
  52.  
  53.     int a = -1;
  54.     cout << '\n';
  55.     for(int i=31; i>=0; i--)
  56.         cout << ((1<<i)&a ? '1' : '0');
  57.     cout <<" a" << " adica " << a;
  58.  
  59.     int b = -2;
  60.     cout << '\n';
  61.     for(int i=31; i>=0; i--)
  62.         cout << ((1<<i)&b ? '1' : '0');
  63.     cout <<" b" << " adica " << b;
  64.  
  65.     for(long long i=0; i<1289367100; i++)
  66.         long long x = i*8;
  67.  
  68.     cout << '\n';
  69.     cout << '\n';
  70.     cout << '\n';
  71.     cout << '\n';
  72.     return 0;
  73. }
Add Comment
Please, Sign In to add comment