Base Converter (Dec / Bin / Hex / Oct)
Convert numbers between decimal, binary, hexadecimal, and octal — all four at once.
Written by Anil Gautam · Updated
How do you convert decimal to binary, octal and hex?
Each base counts in powers of itself. Hexadecimal places are worth 1, 16, 256 and 4096, and the letters A to F stand for the values 10 to 15. To convert by hand, divide by the target base and keep the remainders: 2026 ÷ 16 = 126 remainder 10 (A), 126 ÷ 16 = 7 remainder 14 (E), and 7 ÷ 16 = 0 remainder 7. Reading the remainders from last to first gives 7EA, the same value the Hexadecimal field shows when you type 2026 into Decimal.
Binary and hex line up because one hex digit is exactly four bits. 7EA splits into 0111 1110 1010, and the Binary field shows 11111101010 once the leading zero is dropped. Octal uses groups of three bits counted from the right (11 111 101 010), which gives 3752.
What can you type into each base field?
Each field accepts the digits of its own base in upper or lower case and displays letters as capitals. A leading 0x, 0o or 0b is stripped, so 0xFF pasted into Hexadecimal gives 255 and 0b1010 pasted into Binary gives 10. Copy buttons copy the bare digits. Paste each value into the field for its own base: 0x1F in Decimal reads as 1, because the prefix goes and decimal parsing stops at the F.
Parsing stops at the first character that does not belong to the base. Typing 102 into Binary keeps only 10, so every field shows 2 and the stray digit vanishes. A decimal point ends parsing too, which turns 12.9 into 12. If the very first character is invalid, such as a minus sign or a 2 in Binary, the old value stays and an error like "Invalid value for base 2" appears. Hex values starting with 0B are a trap: 0BAD loses its 0B as if it were a binary prefix and reads as AD (173), so type BAD without the leading zero.
How do negative and very large numbers behave?
Only whole numbers from 0 upward are converted. To see how a computer stores a negative number in a fixed width (two's complement), add 2 to the power of that width first. For -20 in 8 bits, type 236 (256 minus 20) into Decimal, and Binary shows 11101100, the bit pattern of -20 in a signed byte. A 16-bit pattern needs 65,536 added instead.
Values are held as JavaScript numbers, which stay exact up to 9,007,199,254,740,991 (2 to the power 53, minus 1). Above that, the lowest digits are rounded: the largest unsigned 64-bit value, FFFFFFFFFFFFFFFF, appears in Decimal as 18446744073709552000 instead of 18446744073709551615, and the hex field itself rolls over to 10000000000000000. From 22 decimal digits up, Decimal switches to exponent notation, so seventy 1s typed into Binary show as 1.1805916207174113E+21. For letters and words, use the Text to Binary Converter; the RGB to HEX Converter splits a color code into red, green and blue.