|
|
@ -28,7 +28,29 @@ void print_in_hex(uint8_t byte) {
|
|
|
|
cout << endl;
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Äëÿ óäîáñòâà ÷òåíèÿ: ïðîáåëû ìåæäó áàéòàìè, ïî 16 áàéò íà ñòðîêó.
|
|
|
|
|
|
|
|
if ((i + 1) % 16 == 0) {
|
|
|
|
|
|
|
|
cout << '\n';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cout << ' ';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Òåñòèðîâàíèå ôóíêöèè nibble_to_hex
|
|
|
|
// Òåñòèðîâàíèå ôóíêöèè nibble_to_hex
|
|
|
|
//for (int i = 0; i <= 0xf; ++i) {
|
|
|
|
//for (int i = 0; i <= 0xf; ++i) {
|
|
|
|
//assert(nibble_to_hex(i) == nibble_to_hex(i));
|
|
|
|
//assert(nibble_to_hex(i) == nibble_to_hex(i));
|
|
|
@ -52,8 +74,26 @@ int main() {
|
|
|
|
assert(nibble_to_hex(0xf) == 'f');
|
|
|
|
assert(nibble_to_hex(0xf) == 'f');
|
|
|
|
|
|
|
|
|
|
|
|
// Ïå÷àòü áàéòà â øåñòíàäöàòåðè÷íîé è äâîè÷íîé ôîðìå
|
|
|
|
// Ïå÷àòü áàéòà â øåñòíàäöàòåðè÷íîé è äâîè÷íîé ôîðìå
|
|
|
|
uint8_t test_byte = 0x2f;
|
|
|
|
//uint8_t test_byte = 0x2f;
|
|
|
|
print_in_hex(test_byte);
|
|
|
|
//uint8_t test_byte = 0x0;
|
|
|
|
|
|
|
|
//uint8_t test_byte = 0xab;
|
|
|
|
|
|
|
|
//uint8_t test_byte = 0xff;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t u8 = 0x42;
|
|
|
|
|
|
|
|
uint16_t u16 = 0x42;
|
|
|
|
|
|
|
|
uint32_t u32 = 0x42;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "u8 bytes: ";
|
|
|
|
|
|
|
|
print_in_hex(&u8, sizeof(u8));
|
|
|
|
|
|
|
|
std::cout << '\n';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "u16 bytes: ";
|
|
|
|
|
|
|
|
print_in_hex(&u16, sizeof(u16));
|
|
|
|
|
|
|
|
std::cout << '\n';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "u32 bytes: ";
|
|
|
|
|
|
|
|
print_in_hex(&u32, sizeof(u32));
|
|
|
|
|
|
|
|
std::cout << '\n';
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|