SHARE
TWEET

Bitshifting in C++

starbeamrainbowlabs Nov 30th, 2015 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace::std;
  5.  
  6. void main() {
  7.         unsigned int a = 4, b = 8;
  8.  
  9.         cout << "and: " << (a & b) << endl;
  10.         cout << "or: " << (a | b) << endl;
  11.         cout << "xor: " << (a ^ b) << endl;
  12.         cout << "inversion: " << ~a << endl;
  13.  
  14.         int c = 58, d = 15;
  15.  
  16.         cout << "c " << (c & 32) << endl;
  17.         cout << "d " << (d & 32) << endl;
  18.  
  19.         unsigned char e = 221;
  20.         cout << "e " << ~e << endl;
  21.  
  22.         cout << "f ";
  23.         int f = 5;
  24.         for(int i = 0; i < 5; i++)
  25.         {
  26.                 f = f << 1;
  27.                 cout << f << "\t";
  28.         }
  29.         cout << endl;
  30.  
  31.         cout << "g ";
  32.         int g = 341;
  33.         for(int i = 0; i < 5; i++)
  34.         {
  35.                 g = g >> 1;
  36.                 cout << g << "\t";
  37.         }
  38.         cout << g << endl;
  39.  
  40.         system("pause");
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top