Decimal to Hex
Decimal in, hexadecimal out — padded to a real field width, and with the two’s-complement pattern rather than a minus sign when the number is negative.
Runs 100% in your browser•Nothing is uploaded to a server•Free forever
Decimal
Hexadecimal
Converting decimal to hex by hand
Divide by 16, write down the remainder, repeat with the quotient, then read the remainders bottom to top. 47 ÷ 16 is 2 remainder 15, and 2 ÷ 16 is 0 remainder 2, so the digits are 2 and F: 2F. It is the same algorithm the converter above runs, except that it uses BigInt division so the loop stays exact for a number of any length rather than falling apart above 253.
The only thing to memorise is the top six digits, since decimal has no symbols for ten through fifteen:
| Decimal | Hex |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| 10 | A |
| 11 | B |
| 12 | C |
| 13 | D |
| 14 | E |
| 15 | F |
Padding, and why it matters more than it looks
Hex is almost always written to a fixed width, because the width is information. A byte is two hex digits, so 5 is written 05; a 16-bit word is four; a 32-bit word is eight. Writing 5 where the reader expects a byte loses the fact that the high nibble is zero, and in a colour, a register dump or a protocol field that is a real error rather than a cosmetic one. Set a width above and the output is padded for you.
The #RRGGBB in a stylesheet is the everyday case: an RGB triple of 60, 230, 136 has to become 3CE688, with each channel exactly two digits, or the colour is not the colour you asked for.
Landmark values
A handful of decimal numbers come up constantly, and knowing their hex on sight saves a conversion:
| Decimal | Hex | What it usually is |
|---|---|---|
| 10 | A | the first decimal number that needs a letter |
| 15 | F | the largest single hex digit |
| 16 | 10 | one carry — hex's 10 |
| 100 | 64 | no rounder in hex than it is in binary |
| 127 | 7F | the top of a signed byte |
| 128 | 80 | the sign bit of a byte, on its own |
| 255 | FF | a full byte, and every channel of #ffffff |
| 256 | 100 | one byte over — needs two hex digits plus a carry |
| 1000 | 3E8 | a round decimal number that is not round anywhere else |
| 1024 | 400 | a kibibyte |
| 4096 | 1000 | a page of memory on most systems |
| 32767 | 7FFF | the top of a signed 16-bit value |
| 65535 | FFFF | a full 16-bit word, and the highest TCP port |
| 16777215 | FFFFFF | 24-bit colour, all channels full |
| 2147483647 | 7FFFFFFF | the top of a signed 32-bit int |
| 4294967295 | FFFFFFFF | a full 32-bit word |
Negative numbers do not have a natural hex form
You can write -2F and everybody will understand it, but no machine stores a number that way. In a register, a negative number is a two's-complement bit pattern, and that pattern depends on how wide the field is: −1 is FF in eight bits, FFFF in sixteen and FFFFFFFF in thirty-two. Choose a width above and type a negative decimal, and you get the pattern the machine would actually hold rather than a minus sign glued to a positive number.
Related: hex to decimal for the return trip, decimal to binary when you need the bits rather than the digits, and the full converter for every base at once.
More developer tools
- JSON Formatter
- Base64 Encode / Decode
- URL Encoder / Decoder
- Unix Timestamp Converter
- Regex Tester
- UUID Generator (v4 / v7)
- Hash Generator (MD5 / SHA / HMAC)
- JWT Decoder
- Password Generator
- JSON ⇄ CSV Converter
- HTML Entity Encoder / Decoder
- Cron Expression Explainer
- Color Converter
- WCAG Contrast Checker
- All tools on one page (home)