Родитель
53bfac3d72
Сommit
0b88f98f1b
@ -1,73 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
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<uint8_t*>(&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<uint8_t*>(&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;
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче