aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework 1/bitwise_operators.cpp
blob: 65bb50928f6bc43cd5d1a8fcd6edbb0a58ca3b8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Bitwise Operators
#include <bitset>
#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::bitset;

int main(const int argc, char* argv[])
{

	int num = 0xABCD;
	int mask = 0xFFF0;
	int result = num & mask;

	bitset<16> binary_num(0x03);
	bitset<16> binary_mask(0x03);
	bitset<16> binary_result(0x03);

	cout << "Hex:\n";
	cout << "num     = " << "0x"  <<  std::hex << std::uppercase << std::setfill('0') << std::setw(4) << num << endl;
	cout << "mask     = " << "0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << num << endl;
	cout << "result     = " << "0x" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << num << endl;


	cout << "Binary:\n";
	cout << binary_num << endl;
	cout << binary_mask << endl;
	cout << binary_result << endl;


	return true;
}