From e3ed9e7cf63acdcdaa6a8872cb2330d9b024e338 Mon Sep 17 00:00:00 2001 From: GorokhovDE Date: Mon, 23 Dec 2024 10:30:47 +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=B2=20=D0=B4=D0=B2=D0=BE=D0=B8=D1=87=D0=BD=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=B2=D0=B8=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab04/lab04.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lab04/lab04.cpp b/lab04/lab04.cpp index 99a3276..bd4efef 100644 --- a/lab04/lab04.cpp +++ b/lab04/lab04.cpp @@ -58,11 +58,27 @@ void test_print_array_in_hex() { cout << "\n"; } +char bit_digit(uint8_t byte, uint8_t bit) { + return (byte & (1 << bit)) ? '1' : '0'; +} + +void print_in_binary(uint8_t byte) { + for (int8_t bit = 7; bit >= 0; --bit) { + cout << bit_digit(byte, bit); + } +} + +void test_print_in_binary() { + print_in_binary(0x2a); cout << "\n"; // 00101010 +} + + int main() { test_nibble_to_hex(); test_nibbles(); test_print_in_hex(); test_print_array_in_hex(); + test_print_in_binary(); return 0; }