commit e68529c8b0e0058c7f4fa4f7aa4b8ba9755cefae Author: KleptsovKD Date: Mon Feb 3 20:39:33 2025 +0300 nibble_to_hex diff --git a/lab04/.gitignore b/lab04/.gitignore new file mode 100644 index 0000000..6a543be --- /dev/null +++ b/lab04/.gitignore @@ -0,0 +1,4 @@ +/bin +/obj +/lab04.depend +/lab04.layout diff --git a/lab04/lab04.cbp b/lab04/lab04.cbp new file mode 100644 index 0000000..42b65e3 --- /dev/null +++ b/lab04/lab04.cbp @@ -0,0 +1,41 @@ + + + + + + diff --git a/lab04/main.cpp b/lab04/main.cpp new file mode 100644 index 0000000..46f52de --- /dev/null +++ b/lab04/main.cpp @@ -0,0 +1,47 @@ +#include +#include + +using namespace std; + +char nibble_to_hex(uint8_t i) //Conversion to hex format +{ + assert(0x0 <= i && i <= 0xf); + //return "0123456789abcdef"[i]; + if (i < 10) + { + return i + '0'; + } + else + { + return 'a' + (i - 10); + } +} + + + + +int main() +{ + + assert(nibble_to_hex(0x0) == '0'); + assert(nibble_to_hex(0x1) == '1'); + assert(nibble_to_hex(0x2) == '2'); + assert(nibble_to_hex(0x3) == '3'); + assert(nibble_to_hex(0x4) == '4'); + assert(nibble_to_hex(0x5) == '5'); + assert(nibble_to_hex(0x6) == '6'); + assert(nibble_to_hex(0x7) == '7'); + assert(nibble_to_hex(0x8) == '8'); + assert(nibble_to_hex(0x9) == '9'); + assert(nibble_to_hex(0xa) == 'a'); + assert(nibble_to_hex(0xb) == 'b'); + assert(nibble_to_hex(0xc) == 'c'); + assert(nibble_to_hex(0xd) == 'd'); + assert(nibble_to_hex(0xe) == 'e'); + assert(nibble_to_hex(0xf) == 'f'); + + + cout << "Press any key for exit... "; + cin.get(); + return 0; +}