Binary Decimal Converter
Convert between binary, decimal, hex and octal.
Was this tool helpful?
Thanks for the feedback!
Type a binary string to see its decimal, hexadecimal and octal equivalents, or type a decimal number to get its binary, hex and octal forms. There is a single box; the converter decides the direction from what you enter.
How the converter decides which way to go
The rule is simple: if your entry contains only 0s and 1s and is at least two characters long, it is treated as binary. Anything else is treated as a decimal number. That has a few consequences worth knowing:
- Decimal numbers made only of ones and zeros, such as 10, 11, 100 or 101, are read as binary. Typing 10 returns 2, not 1010.
- Decimal input is cut down to a whole number, so 42.9 converts as 42.
- Hex such as
ffis not recognised and comes out as 0. - A negative decimal gets a minus sign in front of its binary digits (−5 becomes −101); the tool does not produce two's complement.
When you need to force a base, or convert from hex, the number base converter lets you choose the input base explicitly.
Decimal to binary by repeated division
Enter 42 and the result is 101010, hex 0x2a and octal 52. To check it by hand, keep dividing by 2 and note the remainders:
42 ÷ 2 = 21 remainder 0 21 ÷ 2 = 10 remainder 1 10 ÷ 2 = 5 remainder 0 5 ÷ 2 = 2 remainder 1 2 ÷ 2 = 1 remainder 0 1 ÷ 2 = 0 remainder 1
Reading the remainders from the bottom up gives 101010. The hex value follows from 42 = 2 × 16 + 10, and 10 is "a" in hex; the octal from 42 = 5 × 8 + 2.
Binary to decimal with place values
Each binary digit is worth double the one to its right. Entering 11111111 gives:
| Bit position | Value | Bit |
|---|---|---|
| 7 to 4 | 128, 64, 32, 16 | 1 1 1 1 |
| 3 to 0 | 8, 4, 2, 1 | 1 1 1 1 |
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, which the tool also shows as 0xff and octal 377. That is the largest value one byte can hold.
Where these conversions turn up
- Subnet masks: 255.255.255.0 is 11111111.11111111.11111111.00000000, which is why it is written /24.
- Linux permissions:
chmod 755is octal; each digit maps to three bits, so 7 = 111 (rwx) and 5 = 101 (r-x). - Colour codes: the FF in #FF8800 is 255 in decimal.
- Microcontroller registers and bit flags, where a setting like 00100100 switches on bits 2 and 5.
Values are held as standard JavaScript numbers, which are exact only up to 9,007,199,254,740,991 (2⁵³ − 1). Binary strings longer than 53 digits will lose precision, so use a big-integer library for 64-bit work.