From 0b88f98f1b6844fa1558a3a3726b7660b7d12eca Mon Sep 17 00:00:00 2001 From: IvanchenkoIS Date: Mon, 23 Dec 2024 18:49:42 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20'3?= =?UTF-8?q?.cpp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3.cpp | 73 ----------------------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 3.cpp diff --git a/3.cpp b/3.cpp deleted file mode 100644 index 34b10dc..0000000 --- a/3.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -using namespace std; - -char to_hex_char(uint8_t value) { - static const char hex_table[] = "0123456789ABCDEF"; - return hex_table[value]; -} - -void print_hex_byte(uint8_t byte) { - cout << to_hex_char(byte >> 4) << to_hex_char(byte & 0x0F); -} - -void print_hex_number(uint16_t value) { - uint8_t* bytes = reinterpret_cast(&value); - print_hex_byte(bytes[0]); - cout << " "; - print_hex_byte(bytes[1]); -} - -void print_binary_byte(uint8_t byte) { - for (int i = 7; i >= 0; --i) { - cout << ((byte >> i) & 1); - } -} - -void print_binary_number(uint16_t value) { - uint8_t* bytes = reinterpret_cast(&value); - print_binary_byte(bytes[0]); - print_binary_byte(bytes[1]); -} - -int main() { - uint16_t input1, input2; - char operation; - - cin >> input1 >> operation >> input2; - - uint16_t outcome; - switch (operation) { - case '&': - outcome = input1 & input2; - break; - case '|': - outcome = input1 | input2; - break; - case '^': - outcome = input1 ^ input2; - break; - default: - cout << "Ошибка: доступны только &, | и ^" << endl; - return 1; - } - - cout << input1 << " " << operation << " " << input2 << endl; - - print_hex_number(input1); - cout << " " << operation << " "; - print_hex_number(input2); - cout << " = "; - print_hex_number(outcome); - cout << endl; - - print_binary_number(input1); - cout << " " << operation << endl; - print_binary_number(input2); - cout << " =" << endl; - print_binary_number(outcome); - cout << endl; - - return 0; -}