#include #include #include #include using namespace std; void print_in_hex(uint8_t byte) { cout << hex << uppercase << static_cast(byte / 16) << static_cast(byte % 16); } void print_in_hex(const void* data, size_t size) { const uint8_t* bytes = static_cast(data); for (size_t i = 0; i < size; ++i) { print_in_hex(bytes[i]); cout << ' '; if ((i + 1) % 16 == 0 || i == size - 1) cout << endl; } cout << dec; } void print_in_binary(uint8_t byte) { bitset<8> bits(byte); cout << bits; } void print_in_binary(const void* data, size_t size) { const uint8_t* bytes = static_cast(data); for (size_t i = 0; i < size; ++i) { print_in_binary(bytes[i]); cout << ' '; if ((i + 1) % 4 == 0 || i == size - 1) cout << endl; } } int main() { setlocale(LC_ALL, "Russian"); cout << "----Тестирование функций печати\n" << endl; cout << "1. Печать отдельных байт:" << endl; uint8_t test_byte = 0xAB; cout << "print_in_hex(0xAB): "; print_in_hex(test_byte); cout << endl; cout << "print_in_binary(0xAB): "; print_in_binary(test_byte); cout << endl; cout << "\n2. Печать массива данных (12 байт):" << endl; uint8_t test_data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C }; cout << "В шестнадцатеричном виде:" << endl; print_in_hex(test_data, sizeof(test_data)); cout << "\nВ двоичном виде:" << endl; print_in_binary(test_data, sizeof(test_data)); cout << "\n3. Печать строки \"Hello\":"; const char* test_string = "Hello"; cout << "\nВ шестнадцатеричном виде:" << endl; print_in_hex(test_string, strlen(test_string) + 1); cout << "\nВ двоичном виде:" << endl; print_in_binary(test_string, strlen(test_string) + 1); cout << "\n4. Печать числа int = 0x12345678:" << endl; int test_int = 0x12345678; cout << "В шестнадцатеричном виде:" << endl; print_in_hex(&test_int, sizeof(test_int)); cout << "\nВ двоичном виде:" << endl; print_in_binary(&test_int, sizeof(test_int)); return 0; }