From 59dbf76198ef8b1c63e553dce6184a8e7928d886 Mon Sep 17 00:00:00 2001 From: MayorovAY Date: Fri, 12 Dec 2025 16:02:59 +0300 Subject: [PATCH] =?UTF-8?q?=D1=87=D0=B0=D1=81=D1=82=D1=8C=201.8=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=2042?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/main.cpp b/main.cpp index eb65a96..1547d8d 100644 --- a/main.cpp +++ b/main.cpp @@ -47,11 +47,16 @@ void print_in_hex(const void* data, size_t size) { } } +char bit_digit(uint8_t byte, uint8_t bit) { + if (byte & (0x1 << bit)) { + return '1'; + } + return '0'; +} void print_in_binary(uint8_t byte) { for (int bit = 7; bit >= 0; --bit) { printf("%d", (byte >> bit) & 1); } - cout<< endl; } void print_in_binary(const void* data, size_t size) { @@ -67,36 +72,21 @@ void print_in_binary(const void* data, size_t size) { } - - int main() { - uint8_t u8 = 0x42; - uint16_t u16 = 0x42; - uint32_t u32 = 0x42; + uint8_t u8 = 42; + uint16_t u16 = 42; + uint32_t u32 = 42; + + cout<< "u8 bytes: "; print_in_hex(u8); - cout<<" "; - cout<< endl; - cout << "u8 bytes: "; - print_in_hex(&u8, sizeof(u8)); - cout<< endl; - cout << "u16 bytes: "; - print_in_hex(&u16, sizeof(u16)); - cout<< endl; - cout << "u32 bytes: "; - print_in_hex(&u32, sizeof(u32)); - cout << '\n'; - print_in_hex(&u8,40); + cout<< endl << "u8 bytes: "; + print_in_binary(u8); + cout << endl << "u16 bytes: "; + print_in_binary(&u16,sizeof(u16)); + cout << "u32 bytes: "; + print_in_binary(&u32,sizeof(u32)); cout<< endl; - printf("%02X", u8); - - - - - cout<< endl << "Enter number: "; - - - return 0; }