Convert hex to binary
To convert a hex value into binary, take each hex digit in turn.
Replace the digit with its four bits.
Join the groups in the same order.
Try it
The value 0xFA as bits. 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 0xFA into binary:
- Take the digit F. The value is 15, which is 1111.
- Take the digit A. The value is 10, which is 1010.
- Join the groups in the same order: 11111010.
Where this is used
A data sheet gives a register reset value in hex.
A binary form shows which bits the reset value sets, which the hex form hides.
A conversion into binary is the first step. Then you write a mask for one field.
A configuration value in a header file is also in hex, so the same conversion applies.
Points to note
- Write all four bits for every digit, with the zeros at the left. The digit 2 is 0010, not 10.
- Do not change the order of the digits. The first hex digit gives the highest four bits.
- The result has four bits for each hex digit. Two digits give one byte, and eight digits give a 32-bit value.
- A hex value with an odd number of digits does not fill a whole number of bytes. Add a zero at the left first.
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
- What is 0xFA in binary?
- The value 0xFA is 11111010. The digit F gives 1111 and the digit A gives 1010.
- Why must I keep the zeros at the left?
- Each digit holds exactly four bit positions. A zero that you omit moves all the later bits to a lower position and changes the value.
- What is 0xFF in binary?
- The value 0xFF is 11111111. All eight bits have the value 1, so 0xFF is the mask for one full byte.
- How many bits does a hex value have?
- Multiply the number of digits by four. A value of four digits, such as 0x12C4, has 16 bits.