Binary Converter

Type in any box to convert between binary, decimal, hexadecimal and octal, or switch to text to turn words into binary. Small numbers get a place-value breakdown.

Example: 42 in binary

10 1010

6 bits, so it fits in 1 byte.

Binary place values

  1. 2⁷0128
  2. 2⁶064
  3. 2⁵132
  4. 2⁴016
  5. 2³18
  6. 2²04
  7. 2¹12
  8. 2⁰01

32 + 8 + 2 = 42

Decimal to binary by repeated division
  1. 42 ÷ 2 = 21 remainder 0
  2. 21 ÷ 2 = 10 remainder 1
  3. 10 ÷ 2 = 5 remainder 0
  4. 5 ÷ 2 = 2 remainder 1
  5. 2 ÷ 2 = 1 remainder 0
  6. 1 ÷ 2 = 0 remainder 1

Read the remainders from the bottom up: 101010

An example: 42. Type in any box to replace it.

Last reviewed:

How binary numbers work

Binary is a base-2 number system that uses only the digits 0 and 1. Each place is worth twice the place to its right, so instead of ones, tens and hundreds you get ones, twos, fours, eights and so on. Computers use it because a circuit that is either on or off can store exactly one binary digit, called a bit.

The first eight binary place values
Place from the rightPower of 2Value
1st2⁰1
2nd2¹2
3rd2²4
4th2³8
5th2⁴16
6th2⁵32
7th2⁶64
8th2⁷128

Example: reading 101010

  1. Line the digits up with their place values: 32, 16, 8, 4, 2, 1
  2. The 1s sit under 32, 8 and 2
  3. 32 + 8 + 2 = 42

Binary 101010 is 42 in decimal.

How to convert decimal to binary

The standard method is repeated division by 2. Divide the number by 2, write down the remainder (always 0 or 1), and keep dividing the answer until you reach 0. The remainders, read from the last one back to the first, are the binary digits.

Example: 42 to binary

  1. 42 ÷ 2 = 21 remainder 0
  2. 21 ÷ 2 = 10 remainder 1
  3. 10 ÷ 2 = 5 remainder 0
  4. 5 ÷ 2 = 2 remainder 1
  5. 2 ÷ 2 = 1 remainder 0
  6. 1 ÷ 2 = 0 remainder 1
  7. Read the remainders from the bottom up: 101010

42 in binary is 101010.

For small numbers, subtracting powers of 2 is often quicker in your head. Take the largest power that fits, subtract it, and repeat: 42 − 32 = 10, 10 − 8 = 2, 2 − 2 = 0. Put a 1 in the 32, 8 and 2 places and a 0 everywhere else, and you get the same 101010.

Binary to hex and octal

Long strings of bits are hard to read, so programmers shorten them. Hexadecimal (base 16) uses 0 to 9 and then A to F for 10 to 15. Because 16 is 2⁴, every hex digit stands for exactly four bits, and one byte is always two hex digits.

Every 4-bit pattern and its hex digit
BinaryHexDecimal
000000
000111
001022
001133
010044
010155
011066
011177
100088
100199
1010A10
1011B11
1100C12
1101D13
1110E14
1111F15

To convert, split the binary into groups of four from the right and swap each group for its hex digit: 1010 1111 becomes AF, which is 175. Web colors use this shorthand. In #FF8800, FF is 255 parts red, 88 is 136 parts green and 00 is no blue. Octal (base 8) works the same way with groups of three bits, which is why a Unix file permission such as 755 maps neatly onto 111 101 101.

How text becomes binary

Text has no binary form until it is encoded. Every character first gets a number, its Unicode code point, and an encoding turns that number into bytes. UTF-8, the encoding most web pages use, stores the 128 basic ASCII characters (English letters, digits and common punctuation) as one byte each, so H is 72, or 01001000, and i is 105, or 01101001.

How many bytes a character takes in UTF-8
Code pointsBytesExamples
U+0000 to U+007F1A, z, 7 and ?
U+0080 to U+07FF2é, ñ, ü and Greek, Cyrillic, Hebrew or Arabic letters
U+0800 to U+FFFF3€ and most Chinese, Japanese and Hindi characters
U+10000 to U+10FFFF4Most emoji and rarer scripts

Example: the euro sign

  1. € is code point U+20AC
  2. That falls in the three-byte range
  3. UTF-8 bytes: 11100010 10000010 10101100, or E2 82 AC in hex

One character, three bytes, 24 bits.

Capital and small letters differ by a single bit. A is 01000001 (65) and a is 01100001 (97); the only change is the bit worth 32, which is why switching case is so cheap for a computer.

Bits, bytes and the largest numbers they hold

With n bits you can write 2ⁿ different patterns, so the largest whole number is 2ⁿ − 1. Every extra bit doubles the range.

BitsLargest unsigned valueSigned range (two's complement)
8 (one byte)255−128 to 127
1665,535−32,768 to 32,767
324,294,967,295−2,147,483,648 to 2,147,483,647
6418,446,744,073,709,551,615−9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Computers usually store negative whole numbers in two's complement: flip every bit of the positive value and add 1. In 8 bits, 5 is 00000101, so −5 is 11111010 + 1 = 11111011. The converter writes negatives with a minus sign and shows the two's complement pattern underneath.

Ordinary JavaScript numbers lose precision above 2⁵³, which is 9,007,199,254,740,992, so this converter does its arithmetic with exact whole numbers of any length instead. A 64-bit value such as 18,446,744,073,709,551,615 comes out as sixteen Fs in hex without losing a digit.

Mistakes to avoid when converting binary

  • Reading the remainders top down. In the division method the first remainder is the rightmost digit, so read from the bottom up.
  • Dropping leading zeros in bytes. 1000001 and 01000001 are the same number, but byte-based tools expect all 8 bits, so pad on the left.
  • Reading 10 as ten. In binary, 10 means two. Writing 0b10, or adding the words base 2, avoids the mix-up.
  • Confusing B with 8. In hex, B is 11, and D (13) is easy to misread as 0. Writing hex in capitals helps.
  • Mixing up bits and bytes. Internet speeds are quoted in bits per second and file sizes in bytes, with 8 bits to a byte. The data storage converter handles those units.

Binary is one of several ways to write the same number. For a much older system that works without place value at all, try the Roman numeral converter.

Sources and further reading

How to use it

  1. 1Choose numbers or text.
  2. 2Type in any box: binary, decimal, hex or octal, or your text.
  3. 3Copy the result you need, and check the breakdown to see how it works.

Questions

How do I convert binary to decimal?

Multiply each digit by its place value (1, 2, 4, 8 and so on, starting from the right) and add the results. 101010 is 32 + 8 + 2 = 42.

How big a number can it convert?

Numbers are handled as exact whole numbers of any length, so 2^64 − 1 comes out as 64 ones in binary and FFFFFFFFFFFFFFFF in hex, with no rounding.

Why does é take two bytes in binary?

Text is stored as UTF-8. English letters, digits and basic punctuation take one byte each, accented letters take two, most other scripts take two or three, and emoji take four.

Also handy: Character Counter, Online Calculator, Percentage Calculator