From f743eab8400488be54231c63464105df11529993 Mon Sep 17 00:00:00 2001 From: GorokhovDE Date: Mon, 23 Dec 2024 10:19:52 +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=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20nibble=5Fto=5Fhex=20=D1=81=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab04/lab04.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lab04/lab04.cpp diff --git a/lab04/lab04.cpp b/lab04/lab04.cpp new file mode 100644 index 0000000..315510a --- /dev/null +++ b/lab04/lab04.cpp @@ -0,0 +1,20 @@ +#include +#include +using namespace std; + +char nibble_to_hex(uint8_t i) { + assert(0x0 <= i && i <= 0xf); + if (i < 10) return '0' + i; + return 'a' + (i - 10); +} + +void test_nibble_to_hex() { + assert(nibble_to_hex(0x0) == '0'); + assert(nibble_to_hex(0xf) == 'f'); + cout << "nibble_to_hex() tests passed!\n"; +} + +int main() { + test_nibble_to_hex(); + return 0; +}