Writing numbers in hex
Hexadecimal packs four bits into each digit, so it is the compact, human-readable way to write binary data: byte values, memory addresses, Unicode code points, colour channels and IDs. Converting from decimal is a matter of dividing by 16 and turning each remainder into a digit, using A to F for 10 to 15.
Byte grouping writes the result in pairs of digits, the way hex editors and packet captures display data.
Worked example
500 ÷ 16 = 31 remainder 4; 31 ÷ 16 = 1 remainder 15 (F); 1 ÷ 16 = 0 remainder 1. Reading the remainders backwards gives 1F4. 65,535, the largest 16-bit value, is FFFF, shown grouped as FF FF.
Upper or lower case
Both are correct and parsers accept either. Many style guides use uppercase in documentation and lowercase in code and CSS; pick whichever your project uses.
How this works
The page parses your decimal input as an exact big integer and writes it in base 16, which matches dividing by 16 and collecting remainders but stays exact for very large values. Digits above 9 are written A–F in the case you choose. With grouping, the result is padded on the left to an even number of digits and split into bytes. The table gives the same value in binary, octal and decimal and its length in bits. A minus sign stays a sign. Each line converts separately.
Frequently asked
How do I convert decimal to hex by hand?
Divide by 16 repeatedly, write each remainder as a hex digit (10 = A … 15 = F) and read them from last to first.
Should I add 0x?
Only in code. 0x is a notation for programming languages, not part of the number.
How do I write a negative number in hex?
This page keeps a minus sign. Programs usually store negatives in two's complement, which depends on the integer width.
Is there a size limit?
No practical limit; the arithmetic is exact.
Sources
- ECMA-262 — ECMAScript Language Specification
- ISO 80000-1:2022 — Quantities and units — Part 1: General
- Wikipedia — Hexadecimal
Reviewed Oct 17, 2026 · test vectors fixtures/dev/decimal-to-hex/