Simvik

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 7

0x3C

printf("%d %d\n", high_digit(0x3C), low_digit(0x3C));

Expected output:

3 12

Learn it first

  • Binary and hexadecimal · Bits, bytes, hex digits and negative numbers, the way hardware actually stores values.

More Binary and hexadecimal problems