0% found this document useful (0 votes)
5 views

Example Bitwise 2

Uploaded by

lysarith09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Example Bitwise 2

Uploaded by

lysarith09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Example: Bitwise

C++ Code:
#include<iostream>
#include<bitset>
using namespace std;

int main(){
int a = 60;//00111100
int b = 13;//00001101
//AND &
int c1 = a & b;//00001100=4+8=12
//OR |
int c2 = a | b;//00111101 = 1+4+8+16+32=61
//XOR ^
int c3 = a ^ b;//00110001 = 1+16+32=49
//Left Shift
int La = a << 3;//111100000=32+64+128+256=480
int Lb = b << 3;//01101000=8+32+64=104
//Right Shift
int Ra = a >> 3;//00111100=00000111.100=1+2+4=7
int Rb = b >> 3;//00001101=00000001.101=1
cout << "----------------------" << endl;
cout << "a: " << a << ": " << bitset<8>(a) << endl;//a: 60
cout << "b: " << b << ": " << bitset<8>(b)<< endl;//b: 13
cout << "a & b: " << c1 << ": " << bitset<8>(c1) << endl;// a & b: 12
cout << "a | b: " << c2 << ": " << bitset<8>(c2) << endl;//a | b: 61
cout << "a ^ b: " << c3 << ": " << bitset<8>(c3) << endl;//a ^ b: 49
cout << "a << 3: " << La << ": " << bitset<8>(La) << endl;//a << 3: 480
cout << "b << 3: " << Lb << ": " << bitset<8>(Lb) << endl;//b << 3: 104
cout << "a >> 3: " << Ra << ": " << bitset<8>(Ra) << endl;//a >> 3: 7
cout << "b >> 3: " << Rb << ": " << bitset<8>(Rb) << endl;//b >> 3: 1
cout << "----------------------" << endl;
return 0;
}
Output:

You might also like