From 157184394d9342fcfd002953fce87c38b78d9a7e Mon Sep 17 00:00:00 2001 From: GorokhovDE Date: Mon, 23 Dec 2024 10:29:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=87=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=B0=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B9=D1=82=20=D0=B2=20hex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab04/lab04.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lab04/lab04.cpp b/lab04/lab04.cpp index 86de7aa..99a3276 100644 --- a/lab04/lab04.cpp +++ b/lab04/lab04.cpp @@ -39,9 +39,30 @@ void test_print_in_hex() { print_in_hex(0xff); cout << "\n"; } +const uint8_t* as_bytes(const void* data) { + return reinterpret_cast(data); +} + +void print_in_hex(const void* data, size_t size) { + const uint8_t* bytes = as_bytes(data); + for (size_t i = 0; i < size; i++) { + print_in_hex(bytes[i]); + cout << ((i + 1) % 16 == 0 ? '\n' : ' '); + } +} + +void test_print_array_in_hex() { + uint32_t u32 = 0x42; + cout << "u32 bytes: "; + print_in_hex(&u32, sizeof(u32)); + cout << "\n"; +} + + int main() { test_nibble_to_hex(); test_nibbles(); test_print_in_hex(); + test_print_array_in_hex(); return 0; }