Родитель
8688e1956e
Сommit
71d455e14d
@ -0,0 +1,65 @@
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <bitset>
|
||||
#include <sstream>
|
||||
|
||||
// Функция для печати 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;
|
||||
}
|
Загрузка…
Ссылка в новой задаче