Return
to tool
Number Bases

Decimal to Hex Converter

Convert decimal to hex instantly — type a number into either field and the other updates as you go. This converter handles positive and negative values, shows the full remainder-division working for your own number, and lets you switch between 8-, 16-, 32- and 64-bit two's complement. Below you'll find a cross-base chart covering decimal, hex, binary and octal in one view, plus the places hex actually shows up: CSS colours, memory addresses, ASCII codes and MAC addresses.

Decimal ↔ Hex Converter

Type in either field and the other updates as you go. No convert button, no direction to pick. Part of our conversions collection.

Bit width
Negative numbers
Pick a bit width to enable signed mode.
Hex letter case
Commas, spaces and underscores are fine. Handles 20-digit values — the full 64-bit range, more than most converters accept.
Digits 0-9 and A-F, up to 16 digits. 0x and # prefixes accepted and stripped.
Show the working

Type a number in either field and the full step-by-step working appears here.

What is hexadecimal?

Hexadecimal is base 16. Where decimal uses ten digits (0-9) and rolls over to a new place at ten, hex uses sixteen — 0 through 9, then A, B, C, D, E and F standing in for ten through fifteen. Roll over happens at sixteen, so decimal 16 is written 10 in hex, and decimal 255 is FF.

The reason hex exists has nothing to do with humans finding it natural and everything to do with binary. Sixteen is two to the fourth power, which means one hex digit maps to exactly four binary digits — a nibble — with no remainder and no arithmetic. F is 1111, 8 is 1000, A is 1010, every time, in every context. That clean four-to-one mapping is why a 32-bit value that would take thirty-two ones and zeros collapses into eight readable hex digits, and why you can convert between hex and binary by substitution rather than by calculation.

Decimal has no such relationship with binary. Ten is not a power of two, so converting decimal to binary means actual division, and long binary strings have no tidy decimal shorthand. Hex is the compromise the computing world settled on: compact enough to read aloud, structured enough to translate to machine representation on sight.

How hex is written

Because a string like 4051 is ambiguous on its own, hex almost always carries a marker. You will see 0x4051 in C, C++, Java, Python, JavaScript and most assembly; #4051 in CSS and design tools; 4051h or $4051 in older assemblers and on some hardware datasheets; and a plain subscript 16 in maths textbooks. All four mean the same number. Our converter accepts the 0x and # forms and strips them silently, so you can paste straight from code or a stylesheet.

  • 0x prefix — C, C++, Java, Python, JavaScript, Go, Rust, most assemblers
  • # prefix — CSS, HTML, graphic design tools, colour pickers
  • h suffix or $ prefix — legacy assembly, hardware datasheets, retro computing
  • Subscript 16 — mathematics and computer science textbooks
  • No prefix at all — hex dumps, MAC addresses, checksums, UUIDs

How to convert decimal to hex by hand

The standard method is repeated division by 16. Divide your decimal number by 16 and write down the whole-number quotient and the remainder. Divide that quotient by 16 and note the new remainder. Keep going until the quotient reaches zero. Then read the remainders from the bottom up — that string, with 10 to 15 replaced by A to F, is your hex number. The reason it runs bottom-to-top is that each division peels off the least significant digit first.

  1. Divide the decimal number by 16.
  2. Write down the quotient and the remainder.
  3. Convert any remainder of 10-15 to its letter: 10=A, 11=B, 12=C, 13=D, 14=E, 15=F.
  4. Replace the number with the quotient and repeat from step 1.
  5. Stop when the quotient is 0.
  6. Read the remainders bottom-to-top. That is your hex value.

Worked example: 789 in hexadecimal

789 divided by 16 is 49 with a remainder of 5. Then 49 divided by 16 is 3 with a remainder of 1. Then 3 divided by 16 is 0 with a remainder of 3, and the quotient has hit zero, so we stop. Reading the remainders bottom-to-top gives 3, 1, 5 — so 789 in decimal is 315 in hexadecimal, usually written 0x315.

StepDivisionQuotientRemainderHex digit
1789 / 164955
249 / 16311
33 / 16033

Worked example: 476 in hexadecimal

476 divided by 16 is 29 with a remainder of 12, and 12 is C. Then 29 divided by 16 is 1 with a remainder of 13, which is D. Then 1 divided by 16 is 0 with a remainder of 1. Reading bottom-to-top: 1, D, C. So 476 in decimal is 1DC in hexadecimal, or 0x1DC. This example is worth working through because it contains two letter digits, which is where hand conversion usually goes wrong.

StepDivisionQuotientRemainderHex digit
1476 / 162912C
229 / 16113D
31 / 16011

The shortcut for numbers under 256

Any decimal from 0 to 255 fits in exactly two hex digits, and there is a faster route than dividing. Split the number into how many 16s it contains and what's left over. For 200: there are twelve 16s in 200 (192), leaving 8. Twelve is C, so 200 is C8. This works because the first hex place is worth 16 and the second is worth 1, so a two-digit hex number is just (first digit x 16) + (second digit). Most everyday hex — colour channels, byte values, ASCII codes — lives entirely in this range, so the shortcut covers more ground than it sounds like it should.

How to convert hex back to decimal

Going the other way is positional expansion, and it is easier than the division method. Number the hex digits from right to left starting at zero. Multiply each digit by 16 raised to its position, then add the results. Letters convert first: A is 10, B is 11, C is 12, D is 13, E is 14, F is 15.

Take 0x315. The rightmost digit 5 sits at position 0, so it contributes 5 x 1 = 5. The middle digit 1 is at position 1, contributing 1 x 16 = 16. The leftmost digit 3 is at position 2, contributing 3 x 256 = 768. Adding those gives 768 + 16 + 5 = 789, which matches the earlier example. Take 0xBEEF: B is 11 at position 3 (11 x 4096 = 45,056), E is 14 at position 2 (14 x 256 = 3,584), E is 14 at position 1 (14 x 16 = 224), F is 15 at position 0 (15 x 1 = 15). Total: 48,879.

Position (right to left)Place value16^nMax digit contribution
0116^015
11616^1240
225616^23,840
34,09616^361,440
465,53616^4983,040
51,048,57616^515,728,640
616,777,21616^6251,658,240
7268,435,45616^74,026,531,840
84,294,967,29616^864,424,509,440

Negative decimals and two's complement

There is no minus sign in hex as computers use it. A negative number is represented by two's complement, which means the answer depends entirely on how many bits you are working in — and that is why no single hex value can be called 'negative five' without saying the width first. None of the eight pages currently ranking for this term handle negative input at all, which is a real gap if you are debugging a register value or reading a memory dump.

The rule is simple: to represent a negative decimal in a given bit width, add it to two raised to that width. For -5 in 8-bit: 256 + (-5) = 251, and 251 in hex is FB. For -5 in 16-bit: 65,536 + (-5) = 65,531, which is FFFB. For -5 in 32-bit: FFFFFFFB. Same number, three different hex strings, all correct in their own context. The leading F digits are the giveaway — in two's complement, a negative number always has its top bit set, so signed values that start with 8 through F are negative.

Use the Signed toggle and bit-width selector in the converter above to switch between these representations without doing the arithmetic. The working panel shows the addition step so you can check it.

Decimal8-bit hex16-bit hex32-bit hex
−1FFFFFFFFFFFFFF
−2FEFFFEFFFFFFFE
−5FBFFFBFFFFFFFB
−10F6FFF6FFFFFFF6
−16F0FFF0FFFFFFF0
−32E0FFE0FFFFFFE0
−50CEFFCEFFFFFFCE
−64C0FFC0FFFFFFC0
−1009CFF9CFFFFFF9C
−12781FF81FFFFFF81
−12880FF80FFFFFF80
−200(overflow)FF38FFFFFF38
−255(overflow)FF01FFFFFF01
−256(overflow)FF00FFFFFF00
−1000(overflow)FC18FFFFFC18
−32768(overflow)8000FFFF8000
−65536(overflow)(overflow)FFFF0000
−1000000(overflow)(overflow)FFF0BDC0

Decimal, hex, binary and octal reference chart

Every competing page on this term shows decimal against hex and stops there. If you are working near the machine you rarely want just one pairing — you want to see the same value in all four bases at once. This chart does that. Rows 0 to 15 are the ones worth memorising, because they are the sixteen hex digits and their four-bit binary patterns; everything above is composition.

Type a decimal or hex value to jump to its row.
DecimalHexBinaryOctal
00000000000
11000000011
22000000102
33000000113
44000001004
55000001015
66000001106
77000001117
880000100010
990000100111
10A0000101012
11B0000101113
12C0000110014
13D0000110115
14E0000111016
15F0000111117
16100001000020
17110001000121
18120001001022
19130001001123
20140001010024
21150001010125
22160001011026
23170001011127
24180001100030
25190001100131
261A0001101032
271B0001101133
281C0001110034
291D0001110135
301E0001111036
311F0001111137
32200010000040
33210010000141
34220010001042
35230010001143
36240010010044
37250010010145
38260010011046
39270010011147
40280010100050
41290010100151
422A0010101052
432B0010101153
442C0010110054
452D0010110155
462E0010111056
472F0010111157
48300011000060
49310011000161
50320011001062
51330011001163
52340011010064
53350011010165
54360011011066
55370011011167
56380011100070
57390011100171
583A0011101072
593B0011101173
603C0011110074
613D0011110175
623E0011111076
633F0011111177
644001000000100
654101000001101
664201000010102
674301000011103
684401000100104
694501000101105
704601000110106
714701000111107
724801001000110
734901001001111
744A01001010112
754B01001011113
764C01001100114
774D01001101115
784E01001110116
794F01001111117
805001010000120
815101010001121
825201010010122
835301010011123
845401010100124
855501010101125
865601010110126
875701010111127
885801011000130
895901011001131
905A01011010132
915B01011011133
925C01011100134
935D01011101135
945E01011110136
955F01011111137
966001100000140
976101100001141
986201100010142
996301100011143
1006401100100144
1016501100101145
1026601100110146
1036701100111147
1046801101000150
1056901101001151
1066A01101010152
1076B01101011153
1086C01101100154
1096D01101101155
1106E01101110156
1116F01101111157
1127001110000160
1137101110001161
1147201110010162
1157301110011163
1167401110100164
1177501110101165
1187601110110166
1197701110111167
1207801111000170
1217901111001171
1227A01111010172
1237B01111011173
1247C01111100174
1257D01111101175
1267E01111110176
1277F01111111177
1288010000000200
1298110000001201
1308210000010202
1318310000011203
1328410000100204
1338510000101205
1348610000110206
1358710000111207
1368810001000210
1378910001001211
1388A10001010212
1398B10001011213
1408C10001100214
1418D10001101215
1428E10001110216
1438F10001111217
1449010010000220
1459110010001221
1469210010010222
1479310010011223
1489410010100224
1499510010101225
1509610010110226
1519710010111227
1529810011000230
1539910011001231
1549A10011010232
1559B10011011233
1569C10011100234
1579D10011101235
1589E10011110236
1599F10011111237
160A010100000240
161A110100001241
162A210100010242
163A310100011243
164A410100100244
165A510100101245
166A610100110246
167A710100111247
168A810101000250
169A910101001251
170AA10101010252
171AB10101011253
172AC10101100254
173AD10101101255
174AE10101110256
175AF10101111257
176B010110000260
177B110110001261
178B210110010262
179B310110011263
180B410110100264
181B510110101265
182B610110110266
183B710110111267
184B810111000270
185B910111001271
186BA10111010272
187BB10111011273
188BC10111100274
189BD10111101275
190BE10111110276
191BF10111111277
192C011000000300
193C111000001301
194C211000010302
195C311000011303
196C411000100304
197C511000101305
198C611000110306
199C711000111307
200C811001000310
201C911001001311
202CA11001010312
203CB11001011313
204CC11001100314
205CD11001101315
206CE11001110316
207CF11001111317
208D011010000320
209D111010001321
210D211010010322
211D311010011323
212D411010100324
213D511010101325
214D611010110326
215D711010111327
216D811011000330
217D911011001331
218DA11011010332
219DB11011011333
220DC11011100334
221DD11011101335
222DE11011110336
223DF11011111337
224E011100000340
225E111100001341
226E211100010342
227E311100011343
228E411100100344
229E511100101345
230E611100110346
231E711100111347
232E811101000350
233E911101001351
234EA11101010352
235EB11101011353
236EC11101100354
237ED11101101355
238EE11101110356
239EF11101111357
240F011110000360
241F111110001361
242F211110010362
243F311110011363
244F411110100364
245F511110101365
246F611110110366
247F711110111367
248F811111000370
249F911111001371
250FA11111010372
251FB11111011373
252FC11111100374
253FD11111101375
254FE11111110376
255FF11111111377
256100100000000400
5001F4111110100764
51220010000000001000
10003E811111010001750
1024400100000000002000
4095FFF1111111111117777
40961000100000000000010000
65535FFFF1111111111111111177777
655361000010000000000000000200000

Hex digit reference

The sixteen hex digits and their nibble patterns. Learn this table and hex-to-binary conversion becomes substitution rather than arithmetic — one hex digit is four binary digits, and you can convert whole binary strings here.

Hex digitDecimal valueBinary nibbleSpoken as
000000zero
110001one
220010two
330011three
440100four
550101five
660110six
770111seven
881000eight
991001nine
A101010ay
B111011bee
C121100see
D131101dee
E141110ee
F151111eff

Common CSS hex colour values

A CSS colour is three decimal channel values — red, green, blue, each 0 to 255 — written as three pairs of hex digits. #FF0000 is red at maximum, green off, blue off. Understanding that #808080 is grey because 128 sits halfway along 0-255 is the moment hex stops being abstract for most designers.

ColourHexR (dec)G (dec)B (dec)
Black#000000000
White#FFFFFF255255255
Red#FF000025500
Lime#00FF0002550
Blue#0000FF00255
Yellow#FFFF002552550
Cyan / Aqua#00FFFF0255255
Magenta / Fuchsia#FF00FF2550255
Grey#808080128128128
Silver#C0C0C0192192192
Maroon#80000012800
Olive#8080001281280
Green#00800001280
Purple#8000801280128
Teal#0080800128128
Navy#00008000128
Orange#FFA5002551650
Pink#FFC0CB255192203
Brown#A52A2A1654242
Gold#FFD7002552150
Indigo#4B0082750130
Violet#EE82EE238130238
Turquoise#40E0D064224208
Alice Blue#F0F8FF240248255

ASCII characters in decimal and hex

Every character your keyboard produces has a numeric code, and hex is how those codes are written in hex dumps, URL encoding and escape sequences. This is the table that answers the 'how do I write a word in hexadecimal' question — you look up each character and string the results together.

Each character becomes its code in hex. Characters outside ASCII use their UTF-8 bytes.
CharacterDecimalHexNotes
(tab)909Escape: \t
(newline)100AEscape: \n
(carriage return)130DEscape: \r
(space)3220URL-encoded as %20
!3321
"3422
#3523Anchor / hex colour prefix
$3624
%3725URL escape character
&3826URL-encoded as %26
'3927
(4028
)4129
*422A
+432B
,442C
-452D
.462E
/472F
04830Digits run 30-39
14931
25032
35133
45234
55335
65436
75537
85638
95739
:583A
;593B
<603C
=613D
>623E
?633F
@6440
A6541Uppercase runs 41-5A
B6642
C6743
D6844
E6945
F7046
G7147
H7248
I7349
J744A
K754B
L764C
M774D
N784E
O794F
P8050
Q8151
R8252
S8353
T8454
U8555
V8656
W8757
X8858
Y8959
Z905A
[915B
\925C
]935D
^945E
_955F
`9660
a9761Lowercase runs 61-7A
b9862
c9963
d10064
e10165
f10266
g10367
h10468
i10569
j1066A
k1076B
l1086C
m1096D
n1106E
o1116F
p11270
q11371
r11472
s11573
t11674
u11775
v11876
w11977
x12078
y12179
z1227A
{1237B
|1247C
}1257D
~1267E
(delete)1277FLast 7-bit ASCII code

Round decimal values developers look up

DecimalHexWhy it comes up
10AFirst letter digit
15FLargest single hex digit
1610First two-digit hex value
3220ASCII space; 32-bit width
6440Common buffer size
10064Round decimal, awkward hex
1277FMax signed 8-bit
12880Min signed 8-bit; midpoint grey
255FFMax unsigned 8-bit; full colour channel
256100One byte of range
512200Sector size
1,0003E8Round decimal thousand
1,024400One kibibyte
2,048800
4,095FFFMax 12-bit
4,0961000One page of memory
8,1922000
16,3844000
32,7677FFFMax signed 16-bit
32,7688000Min signed 16-bit
65,535FFFFMax unsigned 16-bit; port number ceiling
65,5361000064 kibibytes
1,048,576100000One mebibyte
16,777,215FFFFFFMax 24-bit; white in RGB
4,294,967,295FFFFFFFFMax unsigned 32-bit

Where you'll actually meet hex

Most people looking up a decimal-to-hex conversion are not doing base arithmetic for its own sake. They hit a hex value somewhere specific and need to make sense of it. None of the pages currently ranking for this term cover that ground, so here is where hex actually turns up and what it means in each place.

CSS and colour codes

A hex colour is three bytes: #RRGGBB, where each pair is one channel from 0 to 255. #FF0000 is pure red because the red channel is maxed at 255 and the others are zero. Grey values have equal pairs — #808080 is 128 across the board, halfway up each channel. The three-digit shorthand #F00 simply doubles each digit, expanding to #FF0000. When a designer hands you 'RGB 64, 224, 208' and the stylesheet needs turquoise, you are converting three decimals to hex and concatenating: 40, E0, D0 becomes #40E0D0. Eight-digit values like #FF0000CC add a fourth alpha pair — CC is 204, roughly 80% opacity.

Memory addresses and pointers

Debuggers, stack traces and crash logs print addresses in hex because the four-bit alignment makes structure visible. An address ending in 0 or 8 is aligned; a pointer reading 0x7FFF5FBFF8C0 tells you at a glance it is high in the address space. Decimal would hide all of that. Segment boundaries land on round hex numbers too — 0x1000 is 4,096, one memory page — so when you see an address jump from 0x0FFF to 0x1000 you are watching a page boundary being crossed. Converting an address to decimal is mostly useful for arithmetic: subtracting two pointers to get a byte offset is easier in decimal, which is exactly the round trip this converter is for.

ASCII, Unicode and character encoding

Character codes are written in hex almost everywhere they appear. URL encoding uses it — %20 is a space because a space is decimal 32, which is 20 in hex. Unicode code points use the U+ prefix with hex digits, so U+1F600 is the grinning face emoji at decimal 128,512. String escapes in most languages follow the same pattern: \x41 is A, \u00E9 is an accented e. When you dump a file and see 48 65 6C 6C 6F, that is 72, 101, 108, 108, 111 in decimal — 'Hello'.

MAC addresses and network identifiers

A MAC address is six bytes written as twelve hex digits, usually grouped in pairs: 00:1A:2B:3C:4D:5E. The first three bytes identify the manufacturer and the last three identify the device. IPv6 addresses use hex groups too, which is why they look nothing like the decimal dotted quads of IPv4. Subnet masks, VLAN IDs and port numbers cross between the two — port 65535, the highest valid port, is FFFF, which is not a coincidence: it is the largest value that fits in sixteen bits.

File signatures and hex dumps

Files identify themselves in their first few bytes. A PNG starts 89 50 4E 47, a PDF starts 25 50 44 46 — which is %PDF once you convert those to ASCII. A JPEG opens FF D8 FF. Checksums, hashes and UUIDs are all rendered in hex for the same reason: it is the shortest human-readable form that maps cleanly onto the underlying bytes. If you are ever staring at a hex editor trying to work out what a file is, the first four bytes are where you start.

Who uses this and why

Software developers

Reading a register value out of a debugger, setting a bitmask, checking whether an integer overflowed, or converting a pointer offset back to decimal to do arithmetic on it. The bit-width and signed controls matter most here — a value that reads FFFFFFFB in a 32-bit register is -5, and knowing that instantly is the difference between a five-minute bug and an afternoon.

Web designers and front-end developers

Translating between the RGB values a design tool reports and the hex a stylesheet needs. The CSS colour chart above covers the named colours; the converter handles the rest one channel at a time. The copy buttons that emit # prefixed output exist specifically for this job.

Computer science students

Number-base conversion is a first-year staple and it is usually assessed by hand. The step-by-step working panel shows the division trace rather than just the answer, so you can check your own method against it rather than only your result. The cross-base chart is built for revision.

Network and systems engineers

MAC addresses, IPv6 groups, subnet arithmetic, port numbers and packet captures are all hex-native. Converting to decimal is usually about doing range maths — working out how many addresses sit between two values, or whether an ID falls inside an allocated block.

Embedded and hardware engineers

Datasheets specify register addresses and configuration values in hex, often with the older 4051h notation. Firmware constants, memory maps and I2C addresses all live in base 16, and the bit-width selector matters because an 8-bit microcontroller register behaves very differently from a 32-bit one holding the same digits.

Frequently Asked Questions

How do I convert decimal to hex?

Divide the number by 16, note the remainder, then divide the quotient by 16 and note that remainder, repeating until the quotient is zero. Read the remainders from the bottom up, converting 10-15 to A-F. The converter at the top of this page does it instantly and shows the division steps if you want to check the method.

What is 789 in hexadecimal?

789 in decimal is 315 in hexadecimal, written 0x315. The working is three divisions: 789/16 = 49 remainder 5, then 49/16 = 3 remainder 1, then 3/16 = 0 remainder 3. Reading the remainders bottom-to-top gives 315.

What is 476 decimal to hexadecimal?

476 in decimal is 1DC in hexadecimal, or 0x1DC. Dividing gives 476/16 = 29 remainder 12 (C), then 29/16 = 1 remainder 13 (D), then 1/16 = 0 remainder 1. The two letter digits are what make this one a common source of hand-conversion errors.

How do you write "I love you" in hexadecimal?

You convert each character to its ASCII code and write those codes in hex: 49 20 6C 6F 76 65 20 79 6F 75. That is I (73), space (32), l (108), o (111), v (118), e (101), space (32), y (121), o (111), u (117). Use the text input above the ASCII table to do this for any phrase.

How do I convert a negative decimal to hex?

You need to know the bit width first, because negatives are stored as two's complement and the answer changes with width. Add the negative number to 2 raised to the bit width: -5 in 8-bit is 256 - 5 = 251 = FB, but in 16-bit it is FFFB. Turn on the Signed toggle in the converter and pick your width.

What is 255 in hex, and why does it show up everywhere?

255 is FF. It appears constantly because it is the largest value one byte can hold, which makes it the maximum for a colour channel, an 8-bit register, or any single-byte field. When you see FF in a colour code it means that channel is at full intensity.

What's the difference between hex, binary and octal?

They are bases 16, 2 and 8 respectively — three ways of writing the same value. Hex maps one digit to four binary digits, octal maps one digit to three. Hex won out in modern computing because bytes are eight bits, which divides evenly into two hex digits but not into octal. The cross-base chart above shows all four side by side.

Why do hex numbers start with 0x or #?

Because 15 could be fifteen in decimal or twenty-one in hex, so the prefix removes the ambiguity. Programming languages settled on 0x, CSS and design tools on #, and older assemblers on an h suffix or $ prefix. They all mean the same thing, and this converter accepts any of them.

How do I convert hex back to decimal?

Multiply each hex digit by 16 raised to its position counting from the right starting at zero, then add the results. For 0x315: (3 x 256) + (1 x 16) + (5 x 1) = 789. Or just type the hex value into the right-hand field of the converter — both fields are live, so it works in either direction.

What is the largest number this converter handles?

Up to 16 hex digits, which is 18,446,744,073,709,551,615 unsigned — the full 64-bit range. That is deliberately more generous than most converters on this topic, several of which cap input at 19 decimal characters or fewer.

Is hexadecimal the same as base 16?

Yes, they are two names for the same system. Hexadecimal comes from the Greek for six and the Latin for ten. You will also see it shortened to just hex, and in maths notation as a subscript 16 after the number.

Mini About Us

We built this decimal to hex converter because every tool ranking for the term is single-direction, caps its input, and ignores negative numbers entirely. Ours converts live in both directions, covers the full 64-bit range with two's complement support, and prints the actual division working so you can check the method, not just the answer. This site is a part of the ads4good Network.

Read more about Utility Commons here