Convert decimal to hex
To convert a decimal value into hex, divide the value by 16 and keep the remainder.
Repeat the division until the quotient is 0.
Read the remainders backwards, and write each one as a hex digit.
Try decimal to hex conversion in the bit editor
The value 0x12C in a 16-bit register. Edit the expression or select a bit to flip it.
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
0x012C
hex · 16 bits
- value
- 300
Decimal to hex conversion step by step
Convert 300 into hex: The steps follow the value above.
- 300 / 16 = 18 remainder C
- 18 / 16 = 1 remainder 2
- 1 / 16 = 0 remainder 1
- Read the remainders from the last line up: 12C
The weight of each hex position
| Position | Weight | Decimal value |
|---|---|---|
| 0 | 16^0 | 1 |
| 1 | 16^1 | 16 |
| 2 | 16^2 | 256 |
| 3 | 16^3 | 4096 |
| 4 | 16^4 | 65536 |
| 5 | 16^5 | 1048576 |
| 6 | 16^6 | 16777216 |
| 7 | 16^7 | 268435456 |
Where decimal to hex conversion is used
A data sheet gives a register address in hex, so a hex form is easier to compare.
A hex value also shows the bit groups, because one digit covers four bits.
Decimal to hex conversion: points to note
- The digits after 9 are A, B, C, D, E and F. The digit F is 15.
- Hex is not case sensitive. The values 0x12c and 0x12C are the same.
- Three hex digits are not a whole number of bytes. Write 0x012C for a two-byte value.
The full bit editor
The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.
Open this value in the full editorQuestions about decimal to hex conversion
- What is 300 in hex?
- The value 300 is 0x12C. As a two-byte value it is 0x012C.
- What does the prefix 0x mean?
- The prefix 0x marks a hex value. Without the prefix, 12C is not a valid decimal value.
- How many bits is one hex digit?
- One hex digit holds four bits, which gives the values 0 to 15.