Родитель
							
								
									4ebacc97eb
								
							
						
					
					
						Сommit
						2a456a2992
					
				@ -0,0 +1,61 @@
 | 
				
			||||
#include <iostream>
 | 
				
			||||
#include <cstdint>
 | 
				
			||||
#include <iomanip>
 | 
				
			||||
 | 
				
			||||
// Ôóíêöèÿ äëÿ ïå÷àòè çíà÷åíèÿ â øåñòíàäöàòåðè÷íîì âèäå
 | 
				
			||||
void print_in_hex(uint16_t value) {
 | 
				
			||||
    std::cout << std::hex << std::setw(4) << std::setfill('0') << value;
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
// Ôóíêöèÿ äëÿ ïå÷àòè çíà÷åíèÿ â äâîè÷íîì âèäå
 | 
				
			||||
void print_in_binary(uint16_t value) {
 | 
				
			||||
    for (int i = 15; i >= 0; --i) {
 | 
				
			||||
        std::cout << ((value >> i) & 1);
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
int main() {
 | 
				
			||||
    uint16_t operand1, operand2;
 | 
				
			||||
    char operation;
 | 
				
			||||
 | 
				
			||||
    // Ââîä ïåðâîãî îïåðàíäà
 | 
				
			||||
    std::cout << "Enter first operand (hex): ";
 | 
				
			||||
    std::cin >> std::hex >> operand1;
 | 
				
			||||
 | 
				
			||||
    // Ââîä îïåðàòîðà
 | 
				
			||||
    std::cout << "Enter operator (&, |, ^): ";
 | 
				
			||||
    std::cin >> operation;
 | 
				
			||||
 | 
				
			||||
    // Ââîä âòîðîãî îïåðàíäà
 | 
				
			||||
    std::cout << "Enter second operand (hex): ";
 | 
				
			||||
    std::cin >> std::hex >> operand2;
 | 
				
			||||
 | 
				
			||||
    uint16_t result;
 | 
				
			||||
    // Âûïîëíåíèå îïåðàöèè â çàâèñèìîñòè îò ââåäåííîãî îïåðàòîðà
 | 
				
			||||
    switch (operation) {
 | 
				
			||||
        case '&':
 | 
				
			||||
            result = operand1 & operand2;
 | 
				
			||||
            break;
 | 
				
			||||
        case '|':
 | 
				
			||||
            result = operand1 | operand2;
 | 
				
			||||
            break;
 | 
				
			||||
        case '^':
 | 
				
			||||
            result = operand1 ^ operand2;
 | 
				
			||||
            break;
 | 
				
			||||
        default:
 | 
				
			||||
            std::cerr << "Invalid operator" << std::endl;
 | 
				
			||||
            return 1;
 | 
				
			||||
    }
 | 
				
			||||
 | 
				
			||||
    // Âûâîä ðåçóëüòàòà â øåñòíàäöàòåðè÷íîì âèäå
 | 
				
			||||
    std::cout << "Result in hex: ";
 | 
				
			||||
    print_in_hex(result);
 | 
				
			||||
    std::cout << std::endl;
 | 
				
			||||
 | 
				
			||||
    // Âûâîä ðåçóëüòàòà â äâîè÷íîì âèäå
 | 
				
			||||
    std::cout << "Result in binary: ";
 | 
				
			||||
    print_in_binary(result);
 | 
				
			||||
    std::cout << std::endl;
 | 
				
			||||
 | 
				
			||||
    return 0;
 | 
				
			||||
}
 | 
				
			||||
					Загрузка…
					
					
				
		Ссылка в новой задаче