|
|
|
@ -0,0 +1,68 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|