Реализована печать массива байт в hex

main
GorokhovDE 4 месяцев назад
Родитель 89e33de970
Сommit 157184394d

@ -39,9 +39,30 @@ void test_print_in_hex() {
print_in_hex(0xff); cout << "\n"; print_in_hex(0xff); cout << "\n";
} }
const uint8_t* as_bytes(const void* data) {
return reinterpret_cast<const uint8_t*>(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() { int main() {
test_nibble_to_hex(); test_nibble_to_hex();
test_nibbles(); test_nibbles();
test_print_in_hex(); test_print_in_hex();
test_print_array_in_hex();
return 0; return 0;
} }

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