Developer Bases

Decimal to hex

Decimal value
Hexadecimal FF
Divide by 16, keep the remainders
The same number elsewhere
Decimal 255
Binary 11111111
Binary, grouped 1111 1111
Octal 377
Bits needed 8
Note
Divide by 16, read remainders backwards
DecimalBinaryOctalHex
0000
1111
81000108
10101012A
15111117F
16100002010
64100000010040
100110010014464
25511111111377FF
256100000000400100
1024100000000002000400
655351111111111111111177777FFFF
Advertisement
320 × 100

To convert decimal to hexadecimal, divide repeatedly by 16 and read the remainders backwards. 255 gives 15 remainder 15, which is F and F, so FF. Values 10 to 15 are written A to F.

How to convert decimal to hex

1 Enter the decimal number. Spaces, commas and underscores inside it are ignored.
2 Read the hexadecimal result: uppercase, with no 0x prefix on it.
3 Check the bits row if you need to know what width the value takes.
4 Pad the result yourself if it is going somewhere with a fixed number of digits.

The repeated-division method works for any base and is worth understanding rather than memorising. Divide by the target base, note the remainder, divide the quotient again, and continue until the quotient is zero: then read the remainders bottom to top. 48879 divided by 16 gives 3054 remainder 15, then 190 remainder 14, then 11 remainder 14, then 0 remainder 11: F, E, E, B read backwards is BEEF.

Hexadecimal has no fixed width, and that is where this conversion usually goes wrong. 12 comes out as C, one digit, but a colour channel or a byte field wants two: 0C, padded on the left. The CSS three-digit shorthand is not that padding: #f80 means #ff8800, each digit doubled, so you cannot shorten a value by dropping digits from it.

Two limits worth stating. A decimal point is refused rather than truncated, because a hex fraction is a different notation and quietly dropping the part after the point would give an answer that looks right. And a negative number is written with a minus sign in front of the magnitude, which is how a person writes it. The 32-bit pattern a computer actually stores for −255 is FFFFFF01, which is the two’s complement calculator’s job rather than this one’s.

Questions

FF. It is the maximum value of one byte.

Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding