From c2ff39588c48e338fb2a7920fe18791628d0fc38 Mon Sep 17 00:00:00 2001 From: RozhinIV Date: Wed, 15 Jan 2025 12:50:48 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kp3_2.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 kp3_2.cpp diff --git a/kp3_2.cpp b/kp3_2.cpp new file mode 100644 index 0000000..32c4e55 --- /dev/null +++ b/kp3_2.cpp @@ -0,0 +1,68 @@ +#include +#include +#include + +using namespace std; + +void print_in_hex(uint16_t value) +{ + cout << setw(4) << setfill('0') << hex << value; +} + +void print_in_binary(uint16_t value) +{ + for (int bit = 15; bit >= 0; --bit) + { + cout << ((value & (1 << bit)) ? '1' : '0'); + } +} + +int main() +{ + setlocale(LC_ALL, "Russian"); + uint16_t operand1, operand2; + char operation; + + cout << "Введите первый операнд (uint16_t): "; + cin >> operand1; + cout << "Введите оператор (&, |, ^): "; + cin >> operation; + cout << "Введите второй операнд (uint16_t): "; + cin >> operand2; + + uint16_t result; + + switch (operation) + { + case '&': + result = operand1 & operand2; + break; + case '|': + result = operand1 | operand2; + break; + case '^': + result = operand1 ^ operand2; + break; + default: + cout << "Неверный оператор!" << endl; + return 1; + } + + cout << hex << "Hex: "; + print_in_hex(operand1); + cout << " " << operation << " "; + print_in_hex(operand2); + cout << " = "; + print_in_hex(result); + cout << endl; + + cout << "Binary: "; + print_in_binary(operand1); + cout << " " << operation << " "; + print_in_binary(operand2); + cout << " = "; + print_in_binary(result); + cout << endl; + + return 0; +} \ No newline at end of file