number()
takes a byte, and writes its value in hex (as two characters).
Let's examine some parts of the code.
The following extract the high nibble of val
:
(val >> 4)
The following extract the low nibble of val
:
(val & 15)
The following coverts a value between 0 and 15 to the hex digit (0
..9
, A
..F
):
nibble = (...) + '0';
if (nibble > '9') nibble += ('A' - '9' - 1);