Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 4 / bitwise_examples.cpp
blob: e8524ab2b097d53ef0f0383e9de1ceb910995a4a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main()
{
	int a = 13;     // 000...01101
	int b = 20;	    // 000...10100

	int r1 = a & b; // 000...00100(4)
	int r2 = a | b; // 000...11101(29)
	int r3 = a ^ b; // 000...11001(25)
	int r4 = a >> 1;// 000...00110(6)
	int r5 = b << 1;// 000..101000(40)

	std::cout << r1 << endl;
	std::cout << r2 << endl;
	std::cout << r3 << endl;
	std::cout << r4 << endl;
	std::cout << r5 << endl;
}