Decimal to Hex Converter_
A decimal to hex converter that performs the division-remainder method in front of you: every ÷16 step listed with its remainder, then the digits collected in reverse — the same procedure taught in every textbook, executed with big-integer precision so nothing rounds, ever.
Uppercase or lowercase, optional 0x prefix, and a Width setting that turns negative numbers into proper two's-complement bytes instead of refusing them. Try the sample: 61,453 spells something in hex.
- Input
- A decimal number, with spaces or underscores between digit groups if that helps you read it, and a minus sign where you need one.
- Output
- The hexadecimal value in your choice of case, with an optional 0x prefix and digit grouping — and every division that produced it, listed with its remainder.
- Processing
- Worked out in this tab with BigInt arithmetic, so the division-remainder chain is the real one rather than a float approximation of it.
- Limits
- Ten thousand digits in. The division working is printed for values of ten digits or fewer, past which the rows would outnumber the answer.
- Negatives
- A negative number has no hexadecimal form until a width is chosen: −1 is FF in a byte and FFFFFFFF in a word. Commit to a size and the two’s-complement pattern appears; leave Width off and you get −1A, which is notation rather than anything memory could hold.
Decimal to hex by repeated division — worked in full
The division-remainder method on 61,453
How to convert decimal to hex: divide by 16, write down the remainder, and repeat with the quotient until it hits zero — remainders of 10 through 15 become the letters A through F. Run 61,453 through it: ÷16 gives 3,840 remainder 13 (D); 3,840 ÷ 16 gives 240 remainder 0; 240 ÷ 16 gives 15 remainder 0; 15 ÷ 16 gives 0 remainder 15 (F). Collect the remainders last-to-first and you get F00D — yes, really. That is the whole technique, and the panel under the result performs it live on whatever you type.
Why the digits come out backwards
The first division peels off the value of the last hex digit — the ones place — because a remainder mod 16 is exactly what doesn't fit into the higher places. Each subsequent division peels the next place. So the working reads top-to-bottom while the answer reads bottom-to-top, and the final line of the panel says so explicitly. If you've ever gotten a mirrored answer on an exam, this is the step that bit you: the method is right, the collection order was wrong.
Negative numbers need a width before hex means anything
-26 converts happily to -1A — but that's notation, not a bit pattern. Real machines store negatives as two's complement, and the same −1 is FF in a byte, FFFF in 16 bits, and FFFFFFFF in 32 — the hex depends entirely on how many bits you commit to. That is what the Width select settles before it converts anything: commit to a byte, a halfword, a word or a doubleword, and the negative renders as the pattern a debugger or a memory dump would actually print — with a clear error when the number is too large for the size you chose.
The same conversion in Excel and Python
Excel's =DEC2HEX(61453) returns F00D, and it accepts an optional digit count: =DEC2HEX(200, 4) pads to 00C8. Its limits are worth knowing — a 40-bit window, and negatives always occupy all ten characters as 40-bit two's complement, whatever digit count you asked for. Python is unbounded: hex(61453) gives '0xf00d', and format strings control the case and padding — f"{61453:X}" for uppercase, f"{200:04X}" for the padded 00C8. This page's toggles mirror those knobs: case, prefix, and width.
Type the number, read the working, dress the output
- 01Type the decimal number — spaces or underscores between digit groups are fine. It converts on every keystroke; there is nothing to click.
- 02Read the hex result and the binary equivalent under it, then check the division working: each ÷16 row with its remainder, and the reminder that the digits collect in reverse.
- 03Pick output options: uppercase A–F or lowercase, an 0x prefix for code, digit grouping for readability — set once and applied to everything you convert after.
- 04Converting a negative? Choose a Width first, and the two’s-complement pattern appears — then Copy_Result, or hop to the reverse page with the Hex → decimal link.
A worked example for each reason people convert
Color channel to hex pair
A designer hands you rgb(200, 64, 255). Each channel converts separately to two hex digits — three small conversions, then concatenate.
200 · 64 · 255
C8 · 40 · FF → #C840FF
Breakpoint at a decimal address
The profiler reports byte offset 1,048,576. The debugger wants hex. One paste answers it — with the 0x prefix toggle already in code form.
1048576
0x100000
Code point to escape sequence
The em dash is Unicode code point 8212. As hex that's 2014 — which is exactly what goes in the escape.
8212
2014 → "\u2014"
Negative sensor constant for a register
Firmware needs −40 as a signed byte. Width 8-bit renders the two's-complement pattern the register actually stores.
-40
D8
Decimal → hex, 0 through 16
| Decimal | Hex | Decimal | Hex |
|---|---|---|---|
| 0 | 0 | 9 | 9 |
| 1 | 1 | 10 | A |
| 2 | 2 | 11 | B |
| 3 | 3 | 12 | C |
| 4 | 4 | 13 | D |
| 5 | 5 | 14 | E |
| 6 | 6 | 15 | F |
| 7 | 7 | 16 | 10 |
| 8 | 8 | 17 | 11 |
The letters begin at ten and end at fifteen; sixteen rolls over to 10 the way ten rolls over in decimal. After these rows the pattern repeats — 26 is 1A, 42 is 2A, 255 is FF.
Landmarks and byte boundaries
| Decimal | Hex | Why it matters |
|---|---|---|
| 255 | FF | A full byte — two hex digits |
| 256 | 100 | Three digits: you’ve outgrown one byte |
| 4,095 | FFF | Largest 3-digit hex; a classic page size minus one |
| 65,535 | FFFF | Two bytes full — four digits |
| 16,777,215 | FFFFFF | Three bytes: the top of 24-bit color |
| 2,147,483,647 | 7FFFFFFF | Four bytes, top bit clear: INT32_MAX |
The rule underneath: every byte is exactly two hex digits, so digits ÷ 2 (rounded up) tells you the bytes a value occupies. Odd digit counts just mean the leading nibble is small.
Getting hex right the first time
- Doing it by hand? Write the remainders in a column as you divide, then read the column upward — collecting downward is the single most common exam mistake.
- The 0x prefix toggle matters when pasting into code: 100000 is a decimal literal in most languages, 0x100000 is the hex you meant.
- For fixed-width fields, set the Width select even for positives — 200 at 8-bit gives C8, and out-of-range values fail loudly instead of overflowing quietly.
- Uppercase vs lowercase is pure style — CSS colors and Python default to lowercase, many datasheets to uppercase. The toggle exists so you match the destination.
- IDs and timestamps beyond 15-16 decimal digits are past float territory: check any converter with 9007199254740993 (should end …0001 in hex) before trusting it.
- The reverse check is one click: convert, jump via Hex → decimal, paste the result back, and confirm you return to your starting number.
The mistakes that make hex look right and be wrong
A bare minus sign is not two’s complement
−1A is arithmetic notation; no register holds it. Until you fix a width, a negative number has no bit pattern at all — the same −1 is FF, FFFF, or FFFFFFFF depending on the container. Choose the width first; then the hex means something.
0x and # signal different worlds
0x2014 is a number in source code; #2014 would be read as a (broken) color by CSS. The prefix is a context marker, not part of the value — strip or swap it to move between code and stylesheets.
Digit count is not byte count
0x100000 has six hex digits (odd counts happen too) but occupies three bytes — digits ÷ 2, rounding the leading nibble up. Sizing buffers by counting digits without halving is a real and expensive off-by-2x.
Float-based converters corrupt big values silently
Wrong hex looks exactly like right hex — there is no shape to the digits that gives it away, so a corrupted offset travels a long way before anyone notices. A double-precision number stops holding every integer past 9,007,199,254,740,991, so converters that compute in floats emit plausible wrong answers above it. The arithmetic here is arbitrary-precision, and the first integer a double cannot represent — 9,007,199,254,740,993 — is pinned in the test suite.
One number ≠ one color
Colour is three channels, sometimes four, and converting 13,158,600 to C8C8C8 works only because those channels happen to line up. Convert each channel (0–255 → two digits) and concatenate — the per-channel route survives alpha, endianness, and out-of-gamut edits.
Widths, exactness, and what the converter refuses
- Input
- Decimal digits with spaces or underscores as separators, optional +/− sign. Input is capped at 10,000 digits — far past any real register, address or identifier, and short enough that a mispaste cannot lock up the tab.
- Working panel
- Division-remainder rows — value ÷ 16, quotient, remainder with its hex letter — plus the collect-in-reverse reminder. Shown at ten digits or fewer
- Output options
- Uppercase/lowercase A–F · optional
0xprefix · digit grouping in pairs - Width select
- Off/8/16/32/64-bit: pads positives to the width and renders negatives as two's complement, with range errors at both ends
- Arithmetic
- Arbitrary-precision integers throughout; the 2⁵³+1 float boundary is a pinned test
- Readouts
- Hexadecimal primary · binary secondary
- Errors
- Bad characters pinpointed by a caret under the offending spot; fractional input explained instead of truncated
- Network
- None from tool code. A test sweep calls every function this page uses with
fetchandXMLHttpRequestreplaced by stubs that throw, so a stray request fails the build instead of shipping. Disconnect from the network and the page still works.
Questions about converting decimal to hexadecimal
What are the steps to convert decimal to hex by hand?
Repeated division: divide by 16, note the remainder (10–15 become A–F), continue with the quotient, and read the remainders in reverse once you reach zero. The worked 61,453 → F00D example above shows every step, and the tool prints the same table for your own numbers.
Why does my hand calculation come out reversed?
Because the first remainder is the LAST hex digit — each division peels off the lowest remaining place. Collect bottom-to-top. The working panel’s final line repeats this because it is the most common mistake in the method.
How do I convert a negative decimal to hex?
Decide the width first. With Width off you get minus-sign notation (−1A); with a width chosen you get the two’s-complement pattern that size actually stores — -1 becomes FF at 8-bit, FFFF at 16. No width, no meaningful bit pattern.
What are DEC2HEX’s limits in Excel?
It works within 40 bits, and negative inputs always come back as ten characters of 40-bit two’s complement regardless of the places argument. For bigger values or explicit widths, use Python’s hex()/format strings — or this page, which has neither limit.
How many hex digits will my number need?
One per four bits: bytes × 2. Values up to 255 fit two digits, up to 65,535 four, up to 16,777,215 six. The landmarks table above is exactly this progression; odd digit counts simply mean the top nibble is under 16.
Can I turn an RGB color number into a hex code here?
Convert each channel separately: 200 → C8, 64 → 40, 255 → FF, then join as #C840FF. Converting one combined number only works in special cases — per-channel is the route that always holds, and the gotchas explain why.