From 8a6f64ec67e0bf7d7cd829e7ac701de2a5930458 Mon Sep 17 00:00:00 2001 From: Chanin Timbal Date: Thu, 2 May 2024 15:36:00 -0700 Subject: wrote some code for the encoding function in the helper file --- CST 126/Homework 1/bitwise_operators.cpp | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 CST 126/Homework 1/bitwise_operators.cpp (limited to 'CST 126/Homework 1/bitwise_operators.cpp') diff --git a/CST 126/Homework 1/bitwise_operators.cpp b/CST 126/Homework 1/bitwise_operators.cpp new file mode 100644 index 0000000..65bb509 --- /dev/null +++ b/CST 126/Homework 1/bitwise_operators.cpp @@ -0,0 +1,35 @@ +//Bitwise Operators +#include +#include +#include + +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; +} \ No newline at end of file -- cgit v1.2.3