Decimal to Hex Converter
Last updated: 22 August 2026
Reviewed by Gavin · Research and drafting assisted by AI
Decimal to Hex Converter
Decimal (base 10) is the numeral system people learn first and use most. Hexadecimal (base 16) is the numeral system computers print most. Every byte-aligned value in computing, memory addresses, MAC addresses, IPv6 address fragments, CSS colour codes, Unicode code points, Java class-file magic numbers, defaults to hex because each hex digit encodes exactly four binary bits, so a byte is two hex digits, a 32-bit word is eight, a 64-bit pointer is sixteen. This tool converts any non-negative decimal integer you type into its hex equivalent (with binary and octal alongside for cross-checks), with strict input validation, whitespace tolerance, and a cap at the 64-bit safe-integer range.
The conversion is the exact inverse of the site's hex-to-decimal tool. Take any decimal integer in the supported range, convert it through this tool, then paste the resulting hex (without the 0x prefix) into the hex-to-decimal tool and you get the original decimal back. The round trip is exact for every value from 0 up to Number.MAX_SAFE_INTEGER, which is the largest integer JavaScript's Number type can represent without losing precision.
How to Use
- Type or paste a non-negative decimal integer into the input box. Allowed characters are
0-9only, no signs, no letters, no decimal points, no commas. Internal whitespace is removed automatically. - Click Convert (or press Enter). The hex value appears immediately, alongside the lowercase hex, the binary representation, the octal representation, the bit length, and the count of hex digits.
- Use the table for cross-checks:
255decimal should give0xFF,4095decimal should give0xFFF, and4294967295decimal should give0xFFFFFFFF. The round trip back through the hex-to-decimal tool will return the same number. - For values beyond 16 decimal digits, the tool refuses with a clear message, JavaScript's
Number.MAX_SAFE_INTEGERboundary (16 F's worth of hex, or 9 quadrillion and change in decimal) is the supported ceiling. For arbitrarily large integers (UUIDs, IPv6 addresses, SHA-512 hashes), use aBigInt-based tool.
The Formula
The conversion is a single toString call against radix 16, plus three more toString calls to express the same integer in binary, octal, and canonicalised uppercase hex:
hex = decimal.toString(16) // returns lowercase
hex_upper = hex.toUpperCase() // canonical / RFC 5952-ish
binary = decimal.toString(2)
octal = decimal.toString(8)
bits = binary.length
hex_digits = hex.length
The Number.prototype.toString(radix) operation is defined by ECMA-262 Section 21.1.3.7. For radix in the range 2 to 36, it returns a string representation of the integer in that base; lowercase letters are used for digits above 9. For radix=16, the digits are 0-9 and a-f; for radix=2, only 0 and 1; for radix=8, only 0-7. Negative numbers get a leading - sign. Floating-point numbers throw a RangeError because the conversion requires an integer.
The reverse direction (hex to decimal) is parseInt(hex_clean, 16), which is what the site's hex-to-decimal tool does. Pairing the two tools gives you a complete base-10 ↔ base-16 converter; pair again with the binary and octal tools on the site, and you have all four bases 10, 16, 2, 8 covered.
The bit length is the binary string's length. For example, 255 is 11111111 (eight bits), so the displayed bit length is 8; 65535 is 1111111111111111 (sixteen bits); 16777215 is 111111111111111111111111 (twenty-four bits). The number of hex digits required to express a value is ceil(bits / 4), so an 8-bit value always needs two hex digits, a 16-bit value always needs four, and a 32-bit value always needs eight.
The Number.MAX_SAFE_INTEGER ceiling is 9007199254740991, which is 0x1FFFFFFFFFFFFF (53 bits, 13 F's). Beyond that, integer precision is lost because JavaScript's Number is a 64-bit double with only 53 bits of mantissa. Inputs above this boundary are rejected to avoid silently producing wrong values. For values larger than the safe-integer range, use a BigInt-based library or language: BigInt("255").toString(16) works for arbitrary precision.
Worked Examples
1. Single byte: 255 → 0xFF. The maximum value of an unsigned 8-bit byte. Common in CSS colour codes, #FF0000 is full-intensity red, #FFFF00 is yellow, #FFFFFF is white, and as the fill byte for empty memory regions in debugger output. Round trip: paste FF into the hex-to-decimal tool and you get 255 back.
2. ASCII range: 65 → 0x41. The Unicode code point for the Latin capital letter A, written canonically as U+0041. The first 128 code points (the ASCII range) only need two hex digits; the next 1280 need two or three; anything in the Basic Multilingual Plane needs four; supplementary planes need six. Decimal-to-hex conversion is how you find the canonical hex form to look up a character in a Unicode table.
3. Twelve-bit value: 4095 → 0xFFF. The maximum value that fits in 12 bits (a common precision in audio codecs, network addressing, and low-end microcontrollers). Decimal-to-hex conversion of 4095 produces FFF because 4095 = 15×256 + 15×16 + 15 = 16³ - 1. The bit length is exactly 12, which is helpful when choosing a data type or protocol field width.
4. Sixteen-bit range: 65535 → 0xFFFF. The largest 16-bit unsigned value. In TCP/UDP networking, this is the largest valid port number, port 0xFFFF is the bottom of the dynamic/private range. It's also the largest value for an unsigned short in C and the largest addressable offset in a 16-bit real-mode x86 segment. Decimal-to-hex conversion shows up any time you read a network packet header or a memory-mapped I/O register.
5. Twenty-four-bit RGB: 16777215 → 0xFFFFFF. The maximum 24-bit colour, written as #FFFFFF in CSS for pure white. Hexadecimal is the natural way to break a 24-bit value into three 8-bit channels: 0xRRGGBB. The decimal form (16777215) is what you might store in a database column or pass to a graphics API, but the hex form is what a designer reads.
6. Thirty-two-bit unsigned range: 4294967295 → 0xFFFFFFFF. The maximum 32-bit unsigned integer. Equivalent to -1 interpreted as signed 32-bit two's-complement (which is the bit pattern all-ones in any width). In IPv4 routing, this is the broadcast address 255.255.255.255. In Unix file permissions, the octal form 037777777777 represents the same value. Decimal-to-hex conversion from 4294967295 gives FFFFFFFF in lowercase, or 0xFFFFFFFF with the prefix.
7. Sixty-four-bit ceiling: 9007199254740991 → 0x1FFFFFFFFFFFFF. The maximum safe integer in JavaScript. Inputs above this are rejected. The hex form has 13 F's and a leading 1, exactly 53 bits long. This is the boundary that distinguishes "exact integer representation" from "approximate floating-point representation" in JavaScript's Number type, anything bigger should be handled with BigInt or a dedicated arbitrary-precision library.
Where It Shows Up
Hex shows up anywhere a byte-aligned value needs to be printable, and decimal-to-hex is the companion conversion any time a developer or designer needs to back-translate from a decimal reading to the canonical hex form:
- Memory addresses in debugger output. When a debugger prints a pointer like
0x7FFE34A0and you need the decimal offset, decimal-to-hex in reverse gives you the address. When the source is decimal (e.g., a hexadecimal header file with0xnotation stripped), this tool gives you the canonical hex back. - MAC addresses on network hardware. A MAC address like
00:1A:2B:3C:4D:5Eis six bytes written as twelve hex digits, occasionally broken into three four-digit groups. If you have the six byte values in decimal and need to assemble the address, run each through decimal-to-hex to get the canonical two-digit hex form. - IPv6 address fragments. An IPv6 address like
2001:0db8:85a3::8a2e:0370:7334is eight 16-bit groups, each written in hex. Decimal-to-hex is what you use to convert a decimal representation (legacyinet_ntoaoutput, decimal ACL rules, oriptableslogs) into the modern hex colon-delimited form. - Colour codes in HTML and CSS. The standard six-digit
#RRGGBBform is three hex pairs. Decimal-to-hex is how you convert a colour picker output (which often shows decimal RGB triples) into the hex string a developer puts in a stylesheet. - Unicode code points. Every character has an integer code point. The canonical notation is
U+followed by four or more hex digits (e.g.,U+0041forA). Decimal-to-hex gives you the hex from the decimal code point for pasting into HTML entities (A) or escape sequences (\u0041). - File-format magic numbers. Java class files start with
CAFEBABE, PNG images with89504E47, gzip streams with1F8B, ZIP archives with504B0304. Decimal-to-hex is how you reverse-engineer a hex dump back into the form these numbers are documented in, but more commonly, you'll see the decimal value in a field description and need the hex form for byte-level comparison. - Cryptographic hash digests and identifiers. SHA-256 digests are 64 hex characters; SHA-1 digests are 40; MD5 digests are 32. UUIDs are 32 hex characters; database row IDs and Snowflake-style timestamps are sometimes hex for compactness. Decimal-to-hex is one half of the round-trip between database storage format (often decimal
BIGINT) and the wire format (often hex string).
For colour codes specifically, this tool's quick-reference table includes 16777215 → 0xFFFFFF: the maximum 24-bit colour, full red, full green, full blue, pure white. Another common reference is 255 → 0xFF for an 8-bit channel maximum.
Common Mistakes
1. Conflating decimal and hex input. The native parseInt accepts leading 0x to mean hex, but Number.prototype.toString(16) always produces lowercase hex. A user pasting 0xFF into a decimal input gets a parse error (good), but a user pasting FF (no prefix) also gets a parse error (also good, for the same reason). If you want the reverse behaviour, convert a hex value, use the hex-to-decimal tool, which is what parseInt(value, 16) actually does. Mixing up input types is the single most common mistake; both tools exist to make the boundary explicit.
2. Forgetting the leading-zero padding of hex output. Hex values like 0x0001, 0x01, and 0x1 all represent the same integer, but a CSS colour code expects exactly two digits per channel (#FF5733, not #FF573 or #FF5733); a class-file magic expects exactly eight; a MAC address expects exactly twelve. This tool shows the canonical compact form (0xA for the value 10), not the padded form. For fixed-width hex output, use the padStart method or a dedicated formatting function.
3. Treating the result as signed. Hex values above 0x7FFFFFFF represent different things depending on whether you interpret them as signed or unsigned. 0xFFFFFFFF is 4294967295 unsigned but -1 as signed 32-bit two's-complement. This tool always returns the unsigned interpretation, which is the convention in C, JavaScript, and most hex dumps. If your source says a hex value is signed, you need to interpret it as a two's-complement pattern and convert it to a negative number.
4. Going beyond the 64-bit safe range. JavaScript's Number.MAX_SAFE_INTEGER is 9007199254740991 (decimal) or 0x1FFFFFFFFFFFFF (hex), 53 bits of precision. Above that, integer values lose precision: 9007199254740993 and 9007199254740994 parse to the same Number. This tool caps inputs at the safe-integer range and refuses anything larger, rather than silently producing wrong results. For UUIDs, IPv6, SHA-512, or any 128-bit value, use a BigInt-based tool.
5. Case sensitivity in the output. JavaScript's .toString(16) always returns lowercase hex (ff, deadbeef). Hex is conventionally shown uppercase in some contexts (assembly language, Cisco IOS, some Microsoft documentation) and lowercase in others (RFC 5952 for IPv6 canonical, most Unix tools, CSS class names). This tool shows both side-by-side. Always match the case convention to the consumer: HTML/CSS attributes don't care, but some compilers, linkers, and configuration files are case-sensitive.
6. Decimal inputs with signs, commas, or decimal points. This tool refuses any input with characters outside 0-9. A user pasting -255 gets a parse error; a user pasting 1,000 gets a parse error; a user pasting 255.5 gets a parse error. To convert a negative number, convert its absolute value and append -; to convert a thousand-separated number, strip the commas first; to convert a decimal, take the integer part (and accept that the fractional part is lost, base conversion of non-integer rationals is a different operation).
Frequently Asked Questions
Q: What is the largest decimal value this converter accepts? A: The cap is JavaScript's Number.MAX_SAFE_INTEGER, which is 9007199254740991 (decimal) or 0x1FFFFFFFFFFFFF (hex), 53 bits long. Above that boundary, JavaScript's Number type cannot represent every integer exactly, so the tool refuses values beyond it to avoid silently producing wrong answers. For larger values (UUIDs, IPv6, cryptographic hashes), use a BigInt-based tool or library. Concretely, the tool accepts up to 16 decimal digits before the cap kicks in, the decimal 9007199254740991 has 16 digits, so 16 decimal digits is the practical upper bound on the input length.
Q: How do I convert decimal to hex? A: Use the formula value.toString(16), which gives lowercase hex. For example, (255).toString(16) returns "ff"; adding .toUpperCase() gives "FF". For the canonical hex form prefixed with 0x, write (255).toString(16).toUpperCase().padStart(2, '0') if you want fixed two-digit padding, or just '0x' + (255).toString(16).toUpperCase() if you want the shortest canonical form. This tool does exactly that, with binary and octal shown alongside for cross-checks. The reverse direction, hex to decimal, is parseInt("FF", 16), which is what the site's hex-to-decimal tool does.
Q: Why is the output lowercase by default? A: JavaScript's .toString(16) always returns lowercase hex, following ECMA-262 Section 21.1.3.7. The convention is also used by RFC 5952 for canonical IPv6 representation, by most Unix tools (Python's hex(), Ruby's to_s(16)), and by CSS class names and URL fragments where case matters. The uppercase form is preferred in assembly language, Cisco IOS command output, and some Microsoft documentation. This tool shows both forms side-by-side, pick the case that matches your consumer.
Q: Can I convert a negative decimal number? A: Not directly. This tool only accepts non-negative integers. To convert a negative number, take its absolute value, convert the result, and prepend a minus sign: -255 becomes -0xFF. For two's-complement signed representations (the way negative numbers are stored in fixed-width integer types), the interpretation is different, -1 as signed 32-bit is 0xFFFFFFFF, not -0x1. For two's-complement conversion, subtract the result from 2^n where n is the bit width: 255 as signed 8-bit is -1, 65280 as signed 16-bit is -256, etc.
Q: What is the difference between decimal and binary? A: Decimal (base 10) uses ten digits, 0-9. Binary (base 2) uses two digits, 0 and 1. A binary string of length n can represent 2^n distinct values, every doubling adds one more bit. Converting between decimal and binary is the same algorithm as converting to hex, but with radix 2 instead of radix 16. The site includes a dedicated decimal-to-binary converter for that purpose.
Q: How does hexadecimal relate to bytes? A: Each hex digit encodes exactly four binary bits, so two hex digits encode a byte (8 bits), four encode a 16-bit half-word, eight encode a 32-bit word, and sixteen encode a 64-bit double-word. This is why hex is the natural notation for byte-aligned values like memory addresses and network packets, converting between a byte array and its hex representation is trivial, no arithmetic required.
Q: Is this converter suitable for cryptographic or security-sensitive work? A: This is a display utility, not a cryptographic primitive. The decimal-to-hex conversion is exact and deterministic for all values in the supported range, so it is fine for reading numerical IDs, block numbers in a blockchain, decimal-receipted amounts in financial logs, and other non-secret data. It is not appropriate for converting secret keys, password hashes, or HMAC outputs in a context where an attacker might observe the conversion, those should use a vetted cryptographic library on a trusted machine with the secrets handled in memory only. The tool runs entirely in your browser and does not transmit your input anywhere, but the standard "don't paste secrets into web tools" caution still applies.
Q: Can the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal be used for professional or commercial purposes? used for professional or commercial purposes? A: Yes, the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal provides mathematically correct results that are suitable for professional, commercial, and educational use. For the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal, For the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal, For high-stakes applications (medical, legal, financial), verify results with a domain expert. For the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal, the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal formulas used are well-established and validated against reference standards.
How often are the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal formulas updated?mal ⇄ Hex + Binary + Octal formulas updated? A: The formulas are based on established mathematical and computing standards and rarely require updates. When standards change (e.g., new number representations, revised character sets, updated cryptographic hashes), this calculator is updated to reflect the current authoritative source. For the Decimal to Hex Converter, Decimal ⇄ Hex + Binary + Octal, Each calculator's references section lists the specific sources used.
References
- ECMA-262, ECMAScript Language Specification, Section 21.1.3.7
Number.prototype.toString(radix), defines the radix conversion semantics for JavaScript'sNumbertype, including the behavior for radices 2 through 36 and the lowercase digit convention for bases above 10. - ECMA-262, ECMAScript Language Specification, Section 21.1.3.18
parseInt(string, radix), defines the parsing semantics for radix-based integer conversion in JavaScript, including the handling of leading0x/0Xprefixes for radix 16. - IEEE 754, Standard for Floating-Point Arithmetic, defines the 64-bit double-precision representation used by JavaScript's
Numbertype, including theMAX_SAFE_INTEGER = 2^53 - 1 = 0x1FFFFFFFFFFFFFboundary above which integers lose precision. - ISO/IEC 9899, C Programming Language Standard, Section 7.8.2.3
strtouland 7.8.2.4strtoull, defines the parsing semantics for0x-prefixed hex literals in C, whichparseIntmimics, and Section 6.4.4.1 defines the lexical form of decimal and hex integer constants. - RFC 5952, A Recommendation for IPv6 Address Text Representation, IETF, defines the canonical lowercase-no-leading-zeros form for IPv6 address hex groups (this tool uppercases as an option but the canonical form is lowercase).
- The Unicode Standard, Chapter 3, Conformance, Unicode Consortium, defines the
U+followed by four-or-more hex digits notation for code points that the decimal-to-hex conversion enables.