diff options
| author | Chanin Timbal <[email protected]> | 2024-05-31 17:00:30 -0700 |
|---|---|---|
| committer | Chanin Timbal <[email protected]> | 2024-05-31 17:00:30 -0700 |
| commit | abd25f91c773ba9fc3584441aee386e90110b845 (patch) | |
| tree | e29517b26e47f245be2f07d9e27c1cd10a7a971e /CST 126/Homework 1/bitwise_operators.cpp | |
| parent | Purged all previous commits and reset Repo (diff) | |
| parent | wrote some code for the encoding function in the helper file (diff) | |
| download | homework-1-chaninnohea-abd25f91c773ba9fc3584441aee386e90110b845.tar.xz homework-1-chaninnohea-abd25f91c773ba9fc3584441aee386e90110b845.zip | |
Merge branch 'develop' of https://github.com/OIT-WI-2024/homework-1-chaninnohea into develop
Diffstat (limited to 'CST 126/Homework 1/bitwise_operators.cpp')
| -rw-r--r-- | CST 126/Homework 1/bitwise_operators.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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 <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; +}
\ No newline at end of file |