Родитель
8f476f0fe7
Сommit
53bfac3d72
@ -1,72 +0,0 @@
|
|||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
char hex_digit(uint8_t value) {
|
|
||||||
static const char hex_chars[] = "0123456789ABCDEF";
|
|
||||||
return hex_chars[value];
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_hex_byte(uint8_t byte) {
|
|
||||||
cout << hex_digit(byte >> 4) << hex_digit(byte & 0x0F);
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_hex_value(uint16_t data) {
|
|
||||||
uint8_t* bytes = reinterpret_cast<uint8_t*>(&data);
|
|
||||||
display_hex_byte(bytes[0]);
|
|
||||||
cout << " ";
|
|
||||||
display_hex_byte(bytes[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_binary_byte(uint8_t byte) {
|
|
||||||
for (int pos = 7; pos >= 0; --pos) {
|
|
||||||
cout << ((byte >> pos) & 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_binary_value(uint16_t data) {
|
|
||||||
uint8_t* bytes = reinterpret_cast<uint8_t*>(&data);
|
|
||||||
display_binary_byte(bytes[0]);
|
|
||||||
display_binary_byte(bytes[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
uint16_t num1, num2;
|
|
||||||
char op;
|
|
||||||
|
|
||||||
cin >> num1 >> op >> num2;
|
|
||||||
|
|
||||||
uint16_t result;
|
|
||||||
switch (op) {
|
|
||||||
case '&':
|
|
||||||
result = num1 & num2;
|
|
||||||
break;
|
|
||||||
case '|':
|
|
||||||
result = num1 | num2;
|
|
||||||
break;
|
|
||||||
case '^':
|
|
||||||
result = num1 ^ num2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
cout << "Ошибка: доступны только &, | и ^" << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << num1 << " " << op << " " << num2 << endl;
|
|
||||||
|
|
||||||
display_hex_value(num1);
|
|
||||||
cout << " " << op << " ";
|
|
||||||
display_hex_value(num2);
|
|
||||||
cout << " = ";
|
|
||||||
display_hex_value(result);
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
display_binary_value(num1);
|
|
||||||
cout << " " << op << endl;
|
|
||||||
display_binary_value(num2);
|
|
||||||
cout << " =" << endl;
|
|
||||||
display_binary_value(result);
|
|
||||||
cout << endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Загрузка…
Ссылка в новой задаче