From 09482a7dd9db0bdfd952023567cc2a68442d101d Mon Sep 17 00:00:00 2001 From: GorokhovDE Date: Mon, 23 Dec 2024 10:25:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BC=D0=BB=D0=B0=D0=B4=D1=88=D0=B5=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=B8=20=D1=81=D1=82=D0=B0=D1=80=D1=88=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?nibble?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab04/lab04.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lab04/lab04.cpp b/lab04/lab04.cpp index 315510a..cc4e256 100644 --- a/lab04/lab04.cpp +++ b/lab04/lab04.cpp @@ -14,7 +14,22 @@ void test_nibble_to_hex() { cout << "nibble_to_hex() tests passed!\n"; } +uint8_t low_nibble(uint8_t byte) { + return byte & 0x0f; +} + +uint8_t high_nibble(uint8_t byte) { + return byte >> 4; +} + +void test_nibbles() { + assert(low_nibble(0xab) == 0xb); + assert(high_nibble(0xab) == 0xa); + cout << "Nibble extraction tests passed!\n"; +} + int main() { test_nibble_to_hex(); + test_nibbles(); return 0; }