Beetwise

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.

  1. 300 / 16 = 18 remainder C
  2. 18 / 16 = 1 remainder 2
  3. 1 / 16 = 0 remainder 1
  4. Read the remainders from the last line up: 12C

The weight of each hex position

The weight of each hex position
PositionWeightDecimal value
016^01
116^116
216^2256
316^34096
416^465536
516^51048576
616^616777216
716^7268435456

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 editor

Questions 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.