Skip to content
Mathico

Binary Converter & Calculator

Convert binary to decimal, hex and octal, or back again, for numbers of any size including fractions and negatives. You can also do binary arithmetic and turn text into binary, with the working shown.

Mode
Input is

Any size. Fractions (a point) and a leading minus sign are allowed.

Binary

1001 1100

Decimal
156
Hexadecimal
9C
Octal
234
Binary digits (bits)
8
Two's complement width

Signed (two's complement): doesn't fit (range -128 to 127)

Unsigned: 1001 1100

Place values: 128 + 16 + 8 + 4 = 156

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

Binary place values: โ€ฆ 128 64 32 16 8 4 2 1 . ยฝ ยผ โ…› โ€ฆ
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

ProblemBinary resultDecimal check
1011 + 1101000111 + 6 = 17
11001 โˆ’ 1010111125 โˆ’ 10 = 15
1101 ร— 101100000113 ร— 5 = 65
1100 AND 1010100012 AND 10 = 8
1100 XOR 101011012 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

DecBinaryHexDecBinaryHex
000000810008
100011910019
200102101010A
300113111011B
401004121100C
501015131101D
601106141110E
701117151111F

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.