A binary, decimal and hex converter
This binary converter links four ways of writing the same whole number: "Binary (base 2)", "Octal (base 8)", "Decimal (base 10)" and "Hexadecimal (base 16)". Type in one field and the other three follow on every keystroke. The "Text ↔ binary" block turns text into binary code and binary back into text. There is no size limit: 2 to the power of 64 comes out as exactly 18446744073709551616. Everything is calculated in your browser and nothing is sent.
How to use it
- Enter a number in the field for its base. With 10 in decimal you read 1010 in binary, 12 in octal and A in hexadecimal.
- Spaces, underscores, a minus sign and the prefixes
0b,0oand0xare accepted. A digit that does not belong, such as 102 in the binary field, is flagged without wiping the other fields. - Tick "Lowercase hexadecimal" if you prefer ff to FF. Read "Number of bits" and "Bytes", then pick 8, 16, 32 or 64 bits under "Two's complement (signed integer)".
- "Step-by-step working" sets out both conversions with your own number, up to 4,294,967,296.
- In "Text ↔ binary", type some text or paste binary. Every result has its own "Copy" button.
Base 10, base 2, base 16: the idea
A base is the number of digits you have to count with. Decimal has ten, and each place is worth ten times the one to its right. Binary has two, 0 and 1, and each place is worth double the one to its right. Hexadecimal has sixteen: the digits 0 to 9, then the letters A to F for the values 10 to 15.
Decimal to binary: divide by 2
Divide the number by 2, write down the remainder, and repeat with the quotient until it reaches 0. With 25:
| Division | Quotient | Remainder |
|---|---|---|
| 25 ÷ 2 | 12 | 1 |
| 12 ÷ 2 | 6 | 0 |
| 6 ÷ 2 | 3 | 0 |
| 3 ÷ 2 | 1 | 1 |
| 1 ÷ 2 | 0 | 1 |
Read the remainders from bottom to top: 25 is 1 1001 in binary.
Binary to decimal: powers of 2
Going the other way, each bit is multiplied by the power of 2 for its place, starting from 2^0 on the right. For 1101 0110: 128 + 64 + 16 + 4 + 2 = 214.
| Power | Value | Power | Value |
|---|---|---|---|
| 2^0 | 1 | 2^9 | 512 |
| 2^1 | 2 | 2^10 | 1,024 |
| 2^2 | 4 | 2^11 | 2,048 |
| 2^3 | 8 | 2^12 | 4,096 |
| 2^4 | 16 | 2^13 | 8,192 |
| 2^5 | 32 | 2^14 | 16,384 |
| 2^6 | 64 | 2^15 | 32,768 |
| 2^7 | 128 | 2^16 | 65,536 |
| 2^8 | 256 |
Hex, bytes and the number 255
One hexadecimal digit stands for exactly 4 bits, so 1101 0110 reads D6. That makes hex a compact way to write binary. Web colours use it in the form #RRGGBB: #1E90FF means red 30, green 144, blue 255. Memory addresses are written the same way.
A byte is a group of 8 bits and can hold 256 values, from 0 to 255. That is why 255 turns up everywhere: it is 1111 1111, or FF, the largest number one byte can hold. You also meet it in subnet masks such as 255.255.255.0.
Text to binary and negative numbers
The ASCII table gives each unaccented letter a number: "A" is 65, which is 01000001. UTF-8 keeps those codes and adds bytes for other characters: "é" takes two, 11000011 10101001, and "€" takes three, E2 82 AC in hexadecimal. In the other direction, 01001000 01101001 reads "Hi". Pasted code whose length is not a multiple of 8 bits, or which is not valid UTF-8, is flagged with a message.
For negative numbers, computers use two's complement: write the positive value at the chosen width, flip every bit, then add 1. On 8 bits, 42 is 0010 1010 and −42 becomes 1101 0110. A signed byte runs from −128 (1000 0000) to 127, and −1 is 1111 1111. Enter −129 with 8 bits selected and the tool tells you the number does not fit.
These conversions come up in GCSE and A-level Computer Science and in introductory programming courses: the step-by-step working lets you check an exercise line by line.
Frequently asked questions
How do I convert decimal to binary?
Type the number in "Decimal (base 10)". By hand, keep dividing by 2 until the quotient is 0 and read the remainders from bottom to top.
Why is the binary shown in groups of 4 bits?
It is easier to read, and each group matches one hexadecimal digit: 111 1110 1010 reads 7EA, which is 2026.
What is octal used for?
One octal digit is worth 3 bits. You mostly see it in Linux file permissions: 644 stands for 110 100 100.
Why does 255 not fit in 8 signed bits?
Two's complement keeps one bit for the sign, so the largest positive number on 8 bits is 127. Choose 16 bits for 255.