Why hex suits binary values
One hex digit shows exactly four bits.
Two hex digits show exactly one byte.
Hex is shorter than binary, and each digit maps to a fixed group of bits. A decimal digit does not.
Try it
The value 0xFA, which is 11111010. Select a bit to change it. Change the bit width or the signed mode to see the effect.
Name or expression
ID0
ASCII
·
Binary
0b
0b11111010
Hex
0x
0xFA
Decimal
250
Shift
Name or expression
ID0
Binary
0b
Hex
0x
Decimal
ASCII
·
Shift
Sign
Bits
Endian
7
6
5
4
3
2
1
0
Worked example
Convert 11111010 into hex:
- Split the bits into groups of four, from the right: 1111 and 1010.
- Convert the first group: 1111 is F.
- Convert the second group: 1010 is A.
- The result is 0xFA.
Where this is used
A data sheet gives register addresses and reset values in hex.
A hex value shows the bit pattern directly, so a change of one digit changes exactly four bits.
A decimal value hides the bit pattern, which makes a mask hard to read.
Points to note
- A decimal digit does not map to a group of bits. The value 10 in decimal covers parts of two bit groups.
- The prefix 0x marks a hex value. The prefix 0b marks a binary value.
- A hex value with an odd number of digits is not a whole number of bytes. Add a zero at the left for clarity.
The full tool
The full editor holds many values at the same time. It also evaluates expressions across them, and it reads live values from a serial port.
Open the full editorQuestions
- How many bits does one hex digit hold?
- One hex digit holds exactly four bits, which gives the values 0 to 15.
- Why is 0xFF used so often?
- The value 0xFF is one full byte with all bits set. The value is the mask for one byte.
- Is hex the same as binary?
- Hex is a shorter form of the same bits. The value does not change, only the display.