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; +}