Simple Counter is now an Android app.Our Android app is here. Become a founding tester and try it before anyone else.

Join the testers

Number converter · Free · No sign-up

Decimal to Hex Converter

Short answer

To convert decimal to hex, divide by 16 repeatedly, write each remainder as a hex digit (10 to 15 are A to F) and read them from last to first. 48879 gives F, E, E, B, so it is BEEF, and 255 is FF. A negative number becomes a two's complement pattern: -1 is FFFFFFFF in 32 bits.

Every division by 16 shown.

BEEFIn decimal: 48879.48879 in decimal =
  1. Divide 48879 by 16 again and again, writing down each remainder.
  2. 48879 ÷ 16 = 3054 remainder 15 (F)
  3. 3054 ÷ 16 = 190 remainder 14 (E)
  4. 190 ÷ 16 = 11 remainder 14 (E)
  5. 11 ÷ 16 = 0 remainder 11 (B)
  6. Read the remainders from the last to the first: BEEF.
The number in every common base
FormValue
Binary (base 2)1011111011101111
Octal (base 8)137357
Decimal (base 10)48879
Hexadecimal (base 16)BEEF
Binary in groups of four1011 1110 1110 1111

The figures above are an example: put in your own decimal number. Spaces and underscores between digit groups are ignored, and 0b, 0o, 0x or # in front are read when they match the base. Worked out exactly in this browser and kept there; nothing is sent anywhere. Going the other way? Use hex to decimal.

Type a decimal number and read it in hex, with each division by 16 and its remainder listed. Binary and octal are in the table too, and a bit width turns negative numbers into their hex pattern.

Decimal to hex conversion rewrites a base-10 number in base 16, whose digits run 0 to 9 and then A (10) to F (15), so that each hex digit stands for exactly four bits.

  • No sign-up
  • Nothing uploaded
  • Shows every step
  • Works offline
  • Exact, any size

Key facts

Decimal to hex converter at a glance
DetailAnswer
Method shownDivide by 16, write each remainder as 0 to 9 or A to F, read upwards
Example48879 = BEEF; 255 = FF; 1000 = 3E8
FractionsMultiply by 16 and keep the whole parts; repeats in brackets
Negative numbersTwo's complement at 8, 16, 32 or 64 bits: −1 = FFFFFFFF at 32 bits
SizeUp to 256 characters, exact
Where your numbers are keptThis browser only

How to convert decimal to hex by hand

Repeated division by 16, as the converter lists it.

  1. Divide the number by 16

    Write down the whole-number answer and the remainder, 0 to 15.

  2. Write the remainder as a hex digit

    10 is A, 11 B, 12 C, 13 D, 14 E, 15 F.

  3. Divide the answer by 16 again

    Repeat until the answer is 0.

  4. Read the remainders upwards

    The last remainder is the leftmost hex digit.

  5. For a colour, do each channel alone

    And pad each to two digits: 5 is 05.

  6. Check with the converter

    Its working lists the same divisions.

Who converts decimal to hex

Anyone turning an ordinary number into the form computers and standards print.

  • Web designers

    RGB colour channels into a #RRGGBB code.

  • Programmers

    Constants, masks and byte values for code.

  • Students

    Base-16 homework with every division shown.

  • Unicode and HTML writers

    Character numbers into U+ code points and &#x references.

  • Reverse engineers

    Offsets and sizes in the form a hex editor shows.

  • Electronics hobbyists

    Register values for datasheets written in hex.

Decimal RGB to a hex colour code

The most common reason to turn decimal into hex is a colour. CSS and design tools give colours as three channels from 0 to 255, such as rgb(255, 87, 51), and the hex code is just those three numbers in base 16, two digits each, one after the other. The W3C CSS Color Module Level 4 defines it that way: the first pair is red, the second green, the third blue, each from 00 to ff (255), and an optional fourth pair is the alpha.

Decimal RGB to hex colour codes
RGB in decimalEach channel in hexHex code
255, 87, 51FF, 57, 33#FF5733
0, 128, 12800, 80, 80#008080
5, 10, 20005, 0A, C8#050AC8
255, 255, 255FF, FF, FF#FFFFFF
17, 34, 5111, 22, 33#112233, shortened to #123

The step that trips people up is padding. Convert each channel on its own and always write two digits: 5 is 05, not 5, and 10 is 0A. Without the zero, rgb(5, 10, 200) would come out as #5AC8, which is a different four-digit code. Converting the three channels as one big number does not work either. The short three-digit form only exists when each pair is a doubled digit, as in #112233 = #123. To choose a colour and see its hex, RGB and HSL together, use the colour picker. To read a hex code back, use the hex to decimal colour reader.

How many hex digits a value needs

One hex digit is four bits, so the number of hex digits tells you the storage size directly. This is the main reason hex is used for memory and file sizes.

How many hex digits a value needs
Largest valueHexBitsSize
15F4One nibble
255FF8One byte
65,535FFFF16Two bytes
16,777,215FFFFFF24A 24-bit colour
4,294,967,295FFFFFFFF32Four bytes
18,446,744,073,709,551,615FFFFFFFFFFFFFFFF64Eight bytes

Powers of 1024 also look round in hex: 1,024 is 400, 65,536 is 10000 and 1,048,576 is 100000. NIST’s page on binary prefixes gives those as one kibibyte (210 bytes) and one mebibyte (220 bytes), names the IEC approved in December 1998 to tell them apart from the decimal kilobyte and megabyte.

Negative decimals in hex

A negative decimal number in hex is the two’s complement bit pattern written four bits a digit. Pick the width in the converter: the same −1 is FF in a byte and FFFFFFFF in 32 bits, which is why you need to know the width before you can read a hex value as negative.

Negative decimals in hex, by width
Decimal8-bit16-bit32-bit
−1FFFFFFFFFFFFFF
−2FEFFFEFFFFFFFE
−16F0FFF0FFFFFFF0
−12880FF80FFFFFF80
−256Does not fitFF00FFFFFF00

A shortcut for checking: the pattern plus the size of the number is the width’s power of 2. FF (255) + 1 = 256, so FF is −1 at 8 bits; FF80 (65,408) + 128 = 65,536, so FF80 is −128 at 16 bits.

Where decimal numbers are written in hex

Decimal-to-hex conversion comes up wherever a standard writes numbers in hex but people think in decimal.

Where decimal numbers are written in hex
UseDecimalHexWritten as
A Unicode character233E9U+00E9 (é), or é in HTML
An HTML character reference169A9© or © (©)
A network port in a packet dump4431BB01 BB
A byte value200C80xC8
A colour channel8757The middle pair of #FF5733

Unicode code points are always given in hex with at least four digits, so 233 becomes U+00E9; HTML accepts either form, decimal with &# or hex with &#x.

What this page does not do

This page converts numbers. It does not encode text as hex bytes (a string to its UTF-8 bytes), and it does not show how a float is laid out in memory. Up to 256 characters, worked exactly; decimal fractions are converted too, with repeating hex digits in brackets: 0.1 is 0.1(9).

The hex code of a letter or symbol, such as 41 for A, comes from the ASCII to hex converter, which handles whole strings.

What this page does and does not do
It doesIt does not
Whole numbers of any size and decimal fractionsTurn text into hex bytes
Negatives at 8, 16, 32 or 64 bitsShow float or double layouts
Every division by 16, with A to F namedSend your numbers anywhere

This converter or a typical one

This decimal to hex converter compared with a typical one
 This pageA typical one
Every division by 16 shownYes, with A to F namedOften the answer only
Decimal fractionsExact, repeats markedUsually refused
Negative numbersTwo's complement at your widthA fixed width or none
Numbers past 253ExactOften rounded
Your numbers leave the browserNeverVaries

Frequently asked questions

How do you convert decimal to hexadecimal?

Divide by 16 and write down the remainder as a hex digit; divide the answer by 16 again until it reaches 0, then read the remainders from last to first. 300 divided by 16 is 18 remainder 12 (C), then 1 remainder 2, then 0 remainder 1, so 300 is 12C.

What is 255 in hex?

255 is FF: 15 sixteens and 15 ones, the largest two-digit hex number and the largest value of one byte. That is why a colour channel at full strength is FF and why #FFFFFF is white. One more, 256, needs three hex digits: 100.

What is 1000 in hex?

1000 is 3E8 in hex. 1000 divided by 16 is 62 remainder 8; 62 divided by 16 is 3 remainder 14, which is E; and 3 divided by 16 is 0 remainder 3. Read upwards: 3E8. Check: 3 x 256 + 14 x 16 + 8 = 1000.

How do I convert an RGB colour to hex?

Convert each of the three channels on its own and write each as two hex digits, padding with a zero when needed, then put them together after a #. rgb(255, 87, 51) is FF, 57, 33, so #FF5733. Converting the channels as one number gives a wrong code.

Why does hex use the letters A to F?

Base 16 needs sixteen digits and our numerals only go to 9, so the letters A to F stand for 10 to 15. Case does not matter: ff and FF are the same number. The converter prints capitals and reads either.

How do I write a negative number in hex?

In code, negative values are stored as two's complement, so -1 is FF in 8 bits, FFFF in 16 bits and FFFFFFFF in 32. Choose the width in the converter and it shows the pattern and the steps. Written by hand, you can also use a minus sign: -FF is -255.

What is 16 in hex?

16 is 10 in hex: one sixteen and no ones. It is the first two-digit hex number, the same way 10 is in decimal. Writing 0x10 makes the base clear, since 10 alone could be read as ten. In binary, 16 is 10000.

Can decimal fractions be written in hex?

Yes: multiply the fraction by 16 and take the whole part as the next hex digit, repeatedly. 0.5 is 0.8 and 0.75 is 0.C. Most decimal fractions repeat: 0.1 is 0.1999..., written 0.1(9) here, because 10 has a factor of 5 that no power of 16 has.

Open the decimal to hex converter

Free, no sign-up, and what you enter stays in your own browser.