About this tool
The Hex/Binary Converter converts between decimal, binary, hexadecimal, and octal number systems. Enter a value in any base and see all four representations instantly.
About number bases
A base, or radix, is how many distinct digits a positional number system uses. Decimal (base 10) uses 0 to 9. Binary (base 2) uses only 0 and 1. Hexadecimal (base 16) uses 0 to 9 plus A to F. Octal (base 8) uses 0 to 7. The same quantity wears a different costume in each base. The byte value two hundred and fourteen is 214 in decimal, D6 in hex, 11010110 in binary, and 326 in octal. Same value, four spellings.
Computers run on binary because transistors have two stable states: off (0) and on (1). Humans cannot read long binary strings without losing count, so we use hex to read memory dumps, color codes (#FF6633), and MAC addresses. This converter bridges all four bases instantly so you do not have to do the arithmetic by hand.
How base conversion works
Every base uses the same positional logic. Each digit's value is the digit times the base raised to the position index (counting from the right, starting at zero).
Decimal value = sum of (digit_i x base^i) for i = 0 .. n Binary 1101 = 1*8 + 1*4 + 0*2 + 1*1 = 13 Hex D6 = 13*16 + 6*1 = 214 Octal 326 = 3*64 + 2*8 + 6*1 = 214 Bit count = ceil(log2(value + 1))
- Decimal to binary: divide by 2 repeatedly, read remainders bottom-up.
- Binary to hex: group bits in nibbles of 4 from the right; map each nibble (0000 = 0, 1111 = F).
- Hex to decimal: multiply each hex digit by 16 to the power of its position, sum.
- Octal to binary: each octal digit expands to exactly 3 binary digits (5 = 101, 7 = 111).
Worked example
Convert the decimal value 255 across all four bases.
- Decimal: 255 (the maximum value of one unsigned byte).
- Binary: 255 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 11111111. Eight ones.
- Hexadecimal: split 11111111 into two nibbles 1111 and 1111. Each is F. Result: FF.
- Octal: regroup the binary into 3-bit chunks from the right: 011 111 111 = 377.
- Bit count: ceil(log2(256)) = 8 bits, exactly one byte.
Common base size reference
| Bits | Bytes | Unsigned range | Hex range | Use |
|---|---|---|---|---|
| 4 | 0.5 (nibble) | 0 to 15 | 0 to F | One hex digit, BCD |
| 8 | 1 | 0 to 255 | 00 to FF | Byte, ASCII char, color channel |
| 16 | 2 | 0 to 65,535 | 0000 to FFFF | Unicode BMP code point, short int |
| 24 | 3 | 0 to 16,777,215 | 000000 to FFFFFF | RGB color (#RRGGBB), audio sample |
| 32 | 4 | 0 to 4,294,967,295 | 00000000 to FFFFFFFF | IPv4 address, int32, RGBA |
| 48 | 6 | 0 to ~2.8 x 10^14 | 12 hex digits | MAC address |
| 64 | 8 | 0 to ~1.8 x 10^19 | 16 hex digits | int64, timestamp nanoseconds |
Common pitfalls
- Hex case sensitivity. AF and af are the same value. Some parsers reject lowercase or mixed case, so normalise to uppercase before persisting.
- Leading zeros in octal literals. In C, JavaScript, and Python 2, a leading zero (0755) means octal. Drop the zero and you change the value silently. Python 3 requires 0o755.
- Sign extension. Casting a negative 8-bit value to 16 bits without sign extension turns -1 (0xFF) into 255 (0x00FF) instead of -1 (0xFFFF).
- Overflow wrap-around. Adding 1 to 0xFF in an 8-bit register yields 0x00, not 0x100. The converter shows the actual stored value, not the mathematical one.
- Binary string concatenation. Joining "101" + "010" gives "101010" (42), not the bitwise OR. Separate concatenation from arithmetic carefully.
- Color hex shortcut. #F3A is shorthand for #FF33AA, expanding each digit by repeating it. The converter expects full hex, not CSS shorthand.
Related tools
Frequently asked questions
How do I convert decimal to binary by hand?
Repeatedly divide by 2 and read the remainders bottom-up. Example: 13 divided by 2 is 6 remainder 1; 6 divided by 2 is 3 remainder 0; 3 divided by 2 is 1 remainder 1; 1 divided by 2 is 0 remainder 1. Read upwards: 1101. That is 13 in binary, and it matches the converter on this page.
Why do programmers prefer hexadecimal over binary?
Hex is base 16, so every hex digit maps cleanly to exactly 4 binary digits (one nibble). The byte 11010110 becomes D6 in hex, which is much faster to read, dictate over the phone, and remember than the 8 ones and zeros. Hex appears in color codes (#FF6633), memory addresses (0x7FFFC000), and MAC addresses for the same reason.
What is the difference between unsigned and two's complement representation?
An unsigned 8-bit number stores 0 to 255. Two's complement uses the leading bit as a sign and stores -128 to 127 in the same 8 bits. Most CPUs use two's complement because addition and subtraction work identically for positive and negative values. This converter shows unsigned magnitudes; for negative values, calculate the two's complement separately.
How many bits do I need for a given decimal value?
Take the base-2 logarithm of the value and round up. ceil(log2(N+1)) bits suffice. 255 fits in 8 bits, 256 needs 9, 65535 fits in 16, and 4294967295 fills a full 32-bit register. The bit and byte counters on this page apply that formula in real time.
Why is octal still used and where does it appear?
Octal (base 8) groups three binary digits per octal digit. It is mostly legacy now, but it still shows up in Unix file permissions (chmod 755 means owner rwx, group rx, other rx) and in old PDP-11 documentation. Hex took over for most modern uses because 4-bit groups align with bytes more naturally than 3-bit groups.
