From 71d455e14d9eb5d3514140440f58bd1351f646f2 Mon Sep 17 00:00:00 2001 From: SergeevArS Date: Sun, 29 Dec 2024 20:13:17 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB(=D0=B0)=20?= =?UTF-8?q?'=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=E2=84=961'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Задание №1 | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Задание №1 diff --git a/Задание №1 b/Задание №1 new file mode 100644 index 0000000..44113ae --- /dev/null +++ b/Задание №1 @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +// Функция для печати uint16_t в шестнадцатеричном представлении +void print_in_hex(uint16_t value) { + std::cout << std::hex << std::setw(4) << std::setfill('0') << value; +} + +// Функция для печати uint16_t в двоичном представлении +void print_in_binary(uint16_t value) { + std::cout << std::bitset<16>(value); +} + +int main() { + setlocale(LC_ALL, "RUS"); + + uint16_t operand1, operand2; + char operation; + + // Ввод данных пользователем + std::cout << "Введите первый операнд: "; + std::cin >> operand1; + std::cout << "Введите оператор (&, |, ^): "; + std::cin >> operation; + std::cout << "Введите второй операнд: "; + std::cin >> operand2; + + // Выполнение операции + uint16_t result; + switch (operation) { + case '&': + result = operand1 & operand2; + break; + case '|': + result = operand1 | operand2; + break; + case '^': + result = operand1 ^ operand2; + break; + default: + std::cerr << "Неверный оператор!" << std::endl; + return 1; + } + + // Вывод результатов + std::cout << "Результат в шестнадцатеричном виде:\n"; + print_in_hex(operand1); + std::cout << " " << operation << " "; + print_in_hex(operand2); + std::cout << " = "; + print_in_hex(result); + std::cout << std::endl; + + std::cout << "Результат в двоичном виде:\n"; + print_in_binary(operand1); + std::cout << " " << operation << " "; + print_in_binary(operand2); + std::cout << " = "; + print_in_binary(result); + std::cout << std::endl; + + return 0; +} \ No newline at end of file