Split a byte into hex digits
Find the two hex digits of a byte with division and remainder. An easy embedded C problem (Binary and hexadecimal), run and graded in the browser.
easy · Binary and hexadecimal · hexadecimal · nibbles
One hex digit covers exactly four bits, so a byte is always two hex digits. The byte 0xA7 has a high digit of A, which is 10, and a low digit of 7.
Write high_digit and low_digit to return the two hex digits of byte as numbers from 0 to 15. byte is between 0 and 255.
Starter code
int high_digit(int byte) {
return 0;
}
int low_digit(int byte) {
return 0;
}Example tests
0xA7
printf("%d %d\n", high_digit(0xA7), low_digit(0xA7));Expected output:
10 70x3C
printf("%d %d\n", high_digit(0x3C), low_digit(0x3C));Expected output:
3 12Learn it first
- Binary and hexadecimal · Bits, bytes, hex digits and negative numbers, the way hardware actually stores values.
More Binary and hexadecimal problems
- Value of a bit position · Compute how much each bit of a binary number is worth.
- Largest value in n bits · Work out the range of an unsigned number from its width.
- Value of a hex digit · Convert a hexadecimal character into the number it stands for.
- Count the ones · Read off the binary digits of a number one at a time.
- How many bits? · Find the width needed to store a value.
- Read a byte as signed · Interpret the same eight bits as a negative number.