How to use the binary converter
- Convert numbers: pick the base you're typing in (binary, decimal, hex or octal) and enter a number of any size, including fractions and negatives. You'll get every other base, the two's complement pattern and the place-value breakdown.
- Binary math: add, subtract, multiply or divide two binary numbers (with remainder), or combine them with AND, OR and XOR.
- Text โ binary: turn words into 8-bit bytes or decode bytes back into text.
How binary works
Value = ฮฃ digit ร 2^position
10011100โ = 128 + 16 + 8 + 4 = 156โโ ยท 1010.101โ = 8 + 2 + ยฝ + โ = 10.625โโ
Worked examples
Decimal 156 to binary, hex and octal
156 = 128 + 16 + 8 + 4, so the binary is 1001 1100. Grouping four bits at a time gives hex 9C (1001 = 9, 1100 = C), and grouping three bits gives octal 234.
Binary arithmetic
| Problem | Binary result | Decimal check |
|---|---|---|
| 1011 + 110 | 10001 | 11 + 6 = 17 |
| 11001 โ 1010 | 1111 | 25 โ 10 = 15 |
| 1101 ร 101 | 1000001 | 13 ร 5 = 65 |
| 1100 AND 1010 | 1000 | 12 AND 10 = 8 |
| 1100 XOR 1010 | 110 | 12 XOR 10 = 6 |
Negative numbers: โ5 in 8 bits
5 = 00000101 โ flip the bits โ 11111010 โ add 1 โ 11111011. An 8-bit signed value ranges from โ128 to 127.
Decimal, binary and hex from 0 to 15
| Dec | Binary | Hex | Dec | Binary | Hex |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | 10 | 1010 | A |
| 3 | 0011 | 3 | 11 | 1011 | B |
| 4 | 0100 | 4 | 12 | 1100 | C |
| 5 | 0101 | 5 | 13 | 1101 | D |
| 6 | 0110 | 6 | 14 | 1110 | E |
| 7 | 0111 | 7 | 15 | 1111 | F |
Useful landmarks: 255 = 1111 1111 = FF (the largest byte), 1,024 = 2ยนโฐ and 65,535 = FFFF (the largest 16-bit unsigned number).
Where you'll use binary
- Programming: bit flags, masks and permissions use AND, OR and XOR.
- Networking: IP addresses and subnet masks are 32-bit binary numbers.
- Colors: a web color like #FF8800 is three hex bytes: red 255, green 136, blue 0.
- Very large or small numbers: computers store them as binary floating point, a binary version of scientific notation. See the scientific notation converter for the decimal side.
Tips
- Powers of two: a 1 followed by n zeros is 2โฟ, and n ones in a row is 2โฟ โ 1.
- Fractions: only fractions with a power-of-2 denominator terminate. Work with exact fractions in the fraction calculator first, then convert.
- Random bits: need test data? The random number generator makes integers you can convert here.
More math calculators.
Sources
Frequently asked questions
How do I convert binary to decimal?
Multiply each digit by its place value (powers of 2, starting with 1 on the right) and add them up. 10011100 = 128 + 16 + 8 + 4 = 156.
How do I convert decimal to binary?
Divide by 2 repeatedly and write down the remainders, then read them from bottom to top. 13 รท 2 = 6 r1, 6 รท 2 = 3 r0, 3 รท 2 = 1 r1, 1 รท 2 = 0 r1, so 13 = 1101.
How do I convert binary to hexadecimal?
Split the binary number into groups of four bits from the right and replace each group with one hex digit: 1001 1100 = 9C. Each hex digit is exactly four bits, which is why programmers use hex as shorthand for binary.
What is two's complement?
It's how computers store negative integers. To get โn in a fixed number of bits, write n in binary, flip every bit, and add 1. In 8 bits, 5 = 00000101, flipped = 11111010, plus 1 = 11111011, which represents โ5.
How do you add binary numbers?
Like decimal addition, but you carry when a column reaches 2: 0+0 = 0, 0+1 = 1, 1+1 = 10 (write 0, carry 1), 1+1+1 = 11. For example, 1011 + 110 = 10001 (11 + 6 = 17).
Why can't 0.1 be written exactly in binary?
Only fractions whose denominator is a power of 2 terminate in binary. 0.1 = 1/10 repeats forever (0.000110011โฆ), just as 1/3 repeats in decimal. That's why computers sometimes show 0.1 + 0.2 as 0.30000000000000004.
How is text converted to binary?
Each character is encoded as one or more bytes (here using UTF-8, which matches ASCII for English letters), and each byte is written as 8 bits. "H" is 72 = 01001000 and "i" is 105 = 01101001.