Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
48 строки
1.1 KiB
C++
48 строки
1.1 KiB
C++
#include "lab04.h"
|
|
#include "calc_bits.h"
|
|
#include <string>
|
|
|
|
|
|
|
|
void print_in_hex(uint8_t byte) {
|
|
std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte) << " ";
|
|
}
|
|
|
|
void print_in_hex(const void* data, size_t size) {
|
|
const uint8_t* byteData = static_cast<const uint8_t*>(data);
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
print_in_hex(byteData[i]);
|
|
|
|
// Add a space after every 8 bytes for better readability
|
|
if ((i + 1) % 8 == 0) {
|
|
std::cout << " ";
|
|
}
|
|
}
|
|
|
|
std::cout << std::dec << std::endl; // Reset to decimal for further output
|
|
}
|
|
|
|
void print_in_binary(uint8_t byte) {
|
|
for (int i = 7; i >= 0; --i) {
|
|
std::cout << ((byte >> i) & 1);
|
|
}
|
|
std::cout << " ";
|
|
}
|
|
|
|
void print_in_binary(const void* data, size_t size) {
|
|
const uint8_t* byteData = static_cast<const uint8_t*>(data);
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
print_in_binary(byteData[i]);
|
|
|
|
// Add a space after every 8 bytes for better readability
|
|
if ((i + 1) % 8 == 0) {
|
|
std::cout << " ";
|
|
}
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
}
|
|
|