Advertisement
lIlIlIlIIlI

Introduction_bit_test

Sep 9th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main(){
  6.     int a = 3; // 0...0 0011
  7.     int b = 5; // 0...0 0101
  8.     int c = a & b; // 0...0 0001
  9.     int d = a | b; // 0...0 0111
  10.     int e = ~ a; // 1...1 1100
  11.     int f = a ^ b; // 0...0 0110
  12.    
  13.     int g = a << 3; // << 固定補0
  14.     int h = e >> 3; // >> 坐左邊若是1,則補1;若是0,則補0
  15.     int i = a >> 3;
  16.    
  17.     cout << a << endl;
  18.     cout << b << endl;
  19.     cout << c << endl;
  20.     cout << d << endl;
  21.     cout << e << endl;
  22.     cout << f << endl;
  23.    
  24.     cout << g << endl;
  25.     cout << h << endl;
  26.     cout << i << endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement