Article — Decimal to Hexadecimal Converter
The Decimal to Hexadecimal Converter
Hexadecimal is the base-16 number system with digits 0–9 and A–F (representing values 10 through 15). The decimal to hexadecimal conversion is repeated division by 16, collecting remainders. 255 becomes FF, 256 becomes 100, and 65,535 becomes FFFF. One hex digit encodes four bits, and two hex digits encode one byte.
Hex shows up everywhere in computing for one practical reason: it lines up perfectly with bytes. Decimal is great for humans but awkward for machines (one byte spans 0–255, three digits with irregular widths). Binary is great for machines but unreadable for humans. Hex is the working compromise — two characters per byte, easy to read, and trivial to convert back to binary.
What is hexadecimal?
Hexadecimal is a positional number system with sixteen digits. The first ten reuse the decimal digits 0–9. The remaining six use the letters A, B, C, D, E, F to stand for the values 10, 11, 12, 13, 14, 15. Like decimal, each position is a power of the base — but the base is 16 instead of 10, so the second-from-right column is the 16s column, the third is the 256s column, and so on.
Examples make the system click. The hex value A3 equals 10 × 16 + 3 = 163 in decimal. The hex value FF equals 15 × 16 + 15 = 255 — the largest value that fits in one byte. The hex value 1000 is 1 × 16³ + 0 + 0 + 0 = 4,096. The hex value FFFFFFFF is 16⁸ − 1 = 4,294,967,295, the largest 32-bit unsigned integer.
Bell Labs engineers experimented with hexadecimal in the 1960s alongside octal, and IBM standardised on hex for the System/360 architecture in 1964. The choice followed the byte: a byte is 8 bits, two hex digits cover all 256 possible byte values, but you would need three octal digits and waste half the third digit.
The decimal to hexadecimal algorithm
The standard method is repeated division by 16, reading the remainders bottom-up.
step 1 divide N by 16, keep remainderstep 2 repeat on quotient until 0step 3 read remainders bottom-upstep 4 replace 10–15 with A–FWorked example with 1000 decimal: 1000 ÷ 16 = 62 remainder 8. 62 ÷ 16 = 3 remainder 14 (E). 3 ÷ 16 = 0 remainder 3. Bottom-up the remainders are 3, E, 8, so 1000 (dec) = 3E8 (hex). Check by going the other way: 3 × 256 + 14 × 16 + 8 = 768 + 224 + 8 = 1000.
Hexadecimal to decimal (positional sum)
The reverse is a sum of digit × power. Right-to-left, the position values are 1, 16, 256, 4,096, 65,536, and so on. For each digit, multiply by its position value and add up the products.
Worked example with 7F2 hex: 7 × 256 + 15 × 16 + 2 × 1 = 1,792 + 240 + 2 = 2,034. Or in one line: 7F2 hex = 2,034 decimal. The same algorithm scales without modification — 1A2B3C in hex is 1 × 16⁵ + 10 × 16⁴ + 2 × 16³ + 11 × 16² + 3 × 16 + 12 = 1,715,004.
Hex, bytes, and nibbles
Each hex digit represents exactly four bits, a quantity sometimes called a nibble. Two hex digits, eight bits, make one byte. That alignment is why hex dominates over decimal and octal for byte-level work.
The conversion between hex and binary is purely substitutional. Replace each hex digit with its 4-bit binary equivalent: 0 → 0000, 1 → 0001, … A → 1010, … F → 1111. To go backwards, group bits in fours from the right and look each group up. No arithmetic is required at all.
- 1 nibble = 4 bits = 1 hex digit
- 1 byte = 8 bits = 2 hex digits
- 1 word (16-bit) = 16 bits = 4 hex digits
- 1 dword (32-bit) = 32 bits = 8 hex digits
- 1 qword (64-bit) = 64 bits = 16 hex digits
- MAC address = 48 bits = 12 hex digits (commonly with colons)
Hex in color codes and CSS
The most common encounter with hex outside programming is in web design. A CSS color of #FF5733 is three hex bytes for red, green, and blue. FF is full intensity for the red channel (255), 57 is mid-range green (87), 33 is low blue (51). Mixed, that gives a warm orange-red.
The shorthand #F53 expands to #FF5533 by repeating each digit — also valid CSS, also a different orange-red. Modern CSS supports four-digit and eight-digit hex forms that include alpha transparency (#FF5733CC for 80% opaque), but the three-byte form dominates in legacy code and design tools.
When debugging colors, convert the hex pair for each channel separately and read it as 0–255. #80C0E8 is 128, 192, 232 — a soft sky blue. The conversion table for common 0/40/80/C0/FF values (0, 64, 128, 192, 255) covers most colour-picker math.
Hex in memory dumps and addresses
Programmers see hex in memory addresses, register dumps, and crash logs. A 64-bit pointer might read 0x00007FFF80123ABC — sixteen hex digits encoding the address of some object. Most debuggers default to hex display for the same reason colour codes use it: byte alignment, compactness, easy bit-pattern recognition.
Magic numbers in file formats are usually quoted in hex. PNG files start with 89 50 4E 47 (the printable bytes are PNG). PDF starts with 25 50 44 46 (printable: %PDF). ZIP archives start with 50 4B (printable: PK, the initials of co-inventor Phil Katz). Hex makes these signatures readable at a glance.
Why hex instead of octal — a short history
Early computers used a mix of word sizes — 12, 18, 24, 36, even 60 bits — and octal (base 8) was a natural fit because 12, 18, and 36 are all multiples of 3. Octal digits map to three bits each. The DEC PDP-8 and IBM 7090 generations standardised on octal documentation.
The shift to byte-oriented machines in the 1960s changed the math. A byte is 8 bits, which divides cleanly into two 4-bit nibbles but not into three octal digits. Hex won by the end of the decade, and the rise of bytes (and 16-, 32-, 64-bit word sizes that are all multiples of 8) cemented it. Octal survives in a few places — Unix file permissions, escape sequences in some languages — but hex is the default modern radix for non-decimal display.
Common decimal to hex mistakes
Most hex errors are notation errors rather than arithmetic errors. The math is mechanical; the conventions are what trip people up.
- treating leading zero as octal — in C, 0755 is octal 493, not decimal 755 (use 0x for hex)
- skipping the 10→A jump — after 9 the next hex digit is A, not 10
- case confusion — 0xFF and 0xff are identical in value; only style differs
- byte order in multi-byte values — 0x1234 read backwards in memory is often 0x3412 (endian issue, not a conversion bug)
- signed vs unsigned — 0xFF is 255 unsigned, but −1 in 8-bit two's-complement
- mixing # and 0x — # is CSS-only; 0x is programming-language style
JavaScript Number can hold integers up to 2^53 − 1 (≈ 9 × 10¹⁵, or 1FFFFFFFFFFFFF in hex). Larger hex values lose precision in standard JS arithmetic. For 64-bit hex handling, use BigInt or a string-based library. This calculator covers everyday values well within the safe range.