Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
44 строки
1.0 KiB
C++
44 строки
1.0 KiB
C++
#include <iostream>
|
|
#include <bitset>
|
|
#include <cstdint>
|
|
#include <iomanip>
|
|
|
|
int main() {
|
|
uint16_t operand1, operand2;
|
|
char operation;
|
|
|
|
std::cout << "Ââåäèòå ïåðâûé îïåðàíä (0-65535): ";
|
|
std::cin >> operand1;
|
|
|
|
std::cout << "Ââåäèòå îïåðàöèþ (&, |, ^): ";
|
|
std::cin >> operation;
|
|
|
|
std::cout << "Ââåäèòå âòîðîé îïåðàíä (0-65535): ";
|
|
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 << "Ðåçóëüòàò â øåñòíàäöàòåðè÷íîì âèäå: 0x"
|
|
<< std::hex << std::uppercase << result << std::endl;
|
|
|
|
std::cout << "Ðåçóëüòàò â äâîè÷íîì âèäå: "
|
|
<< std::bitset<16>(result) << std::endl;
|
|
|
|
return 0;
|
|
}
|