Артем Рогозин 1 год назад
Родитель 9abe39dd98
Сommit 8b19c6bfbf

@ -0,0 +1,34 @@
#include "calc_bits.h"
#include "lab04.h"
#include <iostream>
#include <iomanip>
uint16_t perform_bitwise_operation(uint16_t operand1, char operation, uint16_t 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. Please use '&', '|', or '^'." << std::endl;
result = 0;
break;
}
return result;
}
void print_calculation(uint16_t result) {
std::cout << "Result in Hex: ";
print_in_hex(result);
std::cout << "\nResult in Binary: ";
print_in_binary(result);
std::cout << std::endl;
}

@ -0,0 +1,7 @@
#ifndef CALC_BITS_H_INCLUDED
#define CALC_BITS_H_INCLUDED
#endif // CALC_BITS_H_INCLUDED

@ -32,6 +32,7 @@
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="calc_bits.cpp" />
<Unit filename="lab04.h" />
<Unit filename="main.cpp" />
<Unit filename="source.cpp" />

@ -2,12 +2,14 @@
#define LAB04_H_INCLUDED
#include <iostream>
#include <iomanip>
#include <cstdint>
#pragma once
void print_in_hex(uint8_t byte);
void print_in_hex(const void* data, size_t size);
void print_in_binary(uint8_t byte);
void print_in_binary(const void* data, size_t size);
uint16_t perform_bitwise_operation(uint16_t operand1, char operation, uint16_t operand2);
void print_calculation(uint16_t result);
#endif // LAB04_H_INCLUDED

@ -22,3 +22,24 @@ int main() {
return 0;
}
int main_calc(){
uint16_t operand1, operand2;
char operation;
cout << "Enter the first operand (in hexadecimal): ";
cin >> std::hex >> operand1;
cout << "Enter the bitwise operation (&, |, or ^): ";
cin >> operation;
cout << "Enter the second operand (in hexadecimal): ";
cin >> std::hex >> operand2;
uint16_t result = perform_bitwise_operation(operand1, operation, operand2);
cout << "\nCalculation Result:" << endl;
print_calculation(result);
return 0;
}

@ -1,7 +1,7 @@
#include "lab04.h"
#include <string>
#include "lab04.h"
#include "calc_bits.h"
void print_in_hex(uint8_t byte) {
std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte) << " ";

Загрузка…
Отмена
Сохранить