diff options
| author | Chanin Timbal <[email protected]> | 2024-05-02 15:36:00 -0700 |
|---|---|---|
| committer | Chanin Timbal <[email protected]> | 2024-05-02 15:36:00 -0700 |
| commit | 8a6f64ec67e0bf7d7cd829e7ac701de2a5930458 (patch) | |
| tree | ed6431470e2f456395c6bee9df0c4e8d31f77ffa /CST 126/Homework 1/bitwise_operators.cpp | |
| parent | Homework 2 first commit (diff) | |
| download | homework-1-chaninnohea-8a6f64ec67e0bf7d7cd829e7ac701de2a5930458.tar.xz homework-1-chaninnohea-8a6f64ec67e0bf7d7cd829e7ac701de2a5930458.zip | |
wrote some code for the encoding function in the helper file
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 |