Hex to Decimal Converter Hex, Decimal, Binary & Octal
Convert between hexadecimal, decimal, binary, and octal instantly. Includes live colour preview for CSS hex codes, bit length display, and real time conversion from any base.
How this hex to decimal converter works, and why hexadecimal exists in the first place
Hexadecimal is base 16, using the digits 0 through 9 and then the letters A through F to stand in for 10 through 15. Programmers reach for it constantly not because computers think in base 16, they think in binary, but because hex is a near perfect shorthand for binary. Every single hex digit maps exactly onto four binary digits, so a byte, eight bits, always fits in exactly two hex characters. That clean alignment is the entire reason hex exists as a human facing notation.
This converter runs on plain JavaScript number parsing in your browser. Nothing you type is sent to a server, and the calculation updates on every keystroke across all four connected fields: hex, decimal, binary, and octal.
Reading a hex digit’s value
parseInt(str, 16), which implements exactly this arithmetic.
toString(2) and toString(8) produce the binary and octal forms directly, rather than converting hex to those bases digit by digit.
| Hex digit | Decimal value | 4-bit binary |
|---|---|---|
| A | 10 | 1010 |
| F | 15 | 1111 |
| FF | 255 | 11111111 |
| 2A | 42 | 00101010 |
The built-in color preview
Type exactly 3 or 6 hex digits and the tool renders a live color swatch, since 6-digit hex is the standard CSS color format used across the web, and 3-digit hex is its shorthand where each digit doubles, so F0A expands to FF00AA. The tool deliberately refuses to guess at any other digit length. Padding a 2-digit value like FF into a color would silently invent a color you never actually specified, so the preview only appears at exactly 3 or 6 digits. It also computes perceived brightness using the standard luminance formula, 0.299R + 0.587G + 0.114B, to decide whether to label the swatch light or dark and to pick readable text color against it.
Byte pair grouping
Longer hex values are grouped into pairs of two characters in the detail view, matching how memory is actually addressed and displayed byte by byte in debuggers and hex editors.
Bit length and byte count
The result panel reports the binary bit length and the number of bytes required to hold the value, useful when you are reasoning about data sizes or storage formats.
- CSS hex color notation defines the 3-digit and 6-digit conventions this tool’s color preview follows.
- Hexadecimal covers the history and the reason base 16 became the standard shorthand for binary.
- Relative luminance explains the brightness formula used to label a swatch light or dark.
Where hex turns up
Reading a memory address or crash dump offset in a debugger, decoding a color value pulled from a design file or screenshot, converting a MAC address segment, checking a hardware error code reported in hex by a driver or BIOS, and translating a hex encoded byte from a network packet capture into a readable decimal count. Hex shows up anywhere raw binary data needs a compact, typo resistant, human readable form, and converting it back to decimal is usually the first step in actually understanding what the value means.
Frequently Asked Questions
Hexadecimal (hex) is a base-16 number system using digits 0 to 9 and letters A to F (where A=10, B=11, C=12, D=13, E=14, F=15). Programmers use it because each hex digit maps exactly to four binary bits (a nibble), making it 4x more compact than binary while preserving a direct, lossless mapping. A byte (8 bits) is always exactly two hex digits. Memory addresses, RGB colour values, hash outputs, file signatures, and machine code offsets are all written in hex because it is far easier to read than long binary strings.
Multiply each hex digit by 16 raised to its position number (counting from 0 at the right). A through F represent 10 through 15. Example: 2F = 2×16^1 + 15×16^0 = 32 + 15 = 47. For a longer value like 1A3: 1×256 + 10×16 + 3×1 = 256 + 160 + 3 = 419. To convert decimal to hex, divide repeatedly by 16 and collect remainders (converting values above 9 to letters), reading from bottom to top.
Each hexadecimal digit represents exactly four binary bits. You can convert between them without going through decimal. To convert hex to binary, replace each hex digit with its 4 bit binary equivalent: 0=0000, 1=0001, …, 9=1001, A=1010, B=1011, C=1100, D=1101, E=1110, F=1111. Example: 4F = 0100 1111 in binary. To go the other way, group binary bits into fours from the right and convert each group. This clean mapping is why hex is preferred over octal or decimal for binary data.
A CSS hex colour code like #FF5733 encodes RGB values. The first two digits (FF) are the red channel in hex (0 to 255), the next two (57) are green, and the last two (33) are blue. FF in hex = 255 decimal (maximum brightness), 00 = 0 (off). So #FF5733 = RGB(255, 87, 51). Short 3 digit codes like #F53 are shorthand for #FF5533, where each digit is doubled. This calculator detects 3 and 6 digit hex values and shows a live colour preview.
For 8 bit (one byte): FF = 255 decimal. For 16 bit: FFFF = 65,535. For 32 bit: FFFFFFFF = 4,294,967,295. For 64 bit: FFFFFFFFFFFFFFFF = 18,446,744,073,709,551,615. These maximums appear frequently in programming as bitmasks, memory limits, and null/invalid sentinels. For signed integers, the maximum positive value is half the unsigned maximum minus one: 7F for 8 bit (127), 7FFFFFFF for 32 bit (2,147,483,647).
They do not. A, B, C, D, E, F and a, b, c, d, e, f represent identical values. The choice is stylistic. Uppercase (0xFF or 0XFF) is common in C, assembly, and many hardware contexts. Lowercase is common in web CSS (#ff5733) and Python. Some hashing algorithms output lowercase hex by convention. This calculator normalises input to uppercase for display but accepts either case.
The 0x prefix is a programming convention, originating in C, that tells the compiler or interpreter the following digits are hexadecimal. Without it, 1A would be ambiguous (is that decimal 1A or hex 1A?). Similarly, 0b marks binary (0b1010) and 0o or 0 marks octal in various languages. In plain mathematical contexts, hex values are often written with a subscript 16 or followed by ‘h’ (1Ah). URL percent encoding uses %XX where XX is a two digit hex value.
A nibble is 4 bits, half a byte. It maps directly to one hexadecimal digit. Nibbles matter because many low level data formats pack two independent 4 bit values into a single byte using the high nibble (bits 7 to 4) and low nibble (bits 3 to 0). BCD (binary coded decimal) stores one decimal digit per nibble. Colour palette formats, file headers, and hardware registers frequently split bytes into nibbles to pack more fields into compact data structures.
From the blog
Number theory, lightly
Base systems, primes and the statistics people get wrong.