EthicalFusion

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 ff is 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 positionValueBit
7 to 4128, 64, 32, 161 1 1 1
3 to 08, 4, 2, 11 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 755 is 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.

Frequently asked questions

Why does 10 convert to 2 instead of 1010?
Any entry of two or more characters made only of 0s and 1s is read as binary, and binary 10 equals decimal 2. Use a base converter with a selectable input base to convert decimal 10.
What is 255 in binary?
255 is 11111111 in binary, 0xff in hex and 377 in octal. It is the maximum value of a single byte.
Can I convert hexadecimal with this tool?
Hex input is not recognised here. Enter the decimal value, or use the Number Base Converter, which accepts hex as the input base.
Why do hex results start with 0x?
0x is the prefix used in C, JavaScript, Python and many other languages to mark a number as hexadecimal.
Does it show negative numbers in two's complement?
No. A negative decimal is shown as a minus sign followed by the binary of its absolute value.

Related tools

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.