Decimal to Binary Converter
Decimal to binary with each division by 2, padding to 8–64 bits, two’s complement and fractions.
This binary calculator adds, subtracts, multiplies and divides binary numbers with steps, and runs bitwise AND, OR, XOR, NOT and shifts.
1101 + 1011 (8-bit)
0001 1000
24 in decimal (unsigned)
A + B gives 0001 1000 in 8 bits: 24 unsigned, and the same signed.
| Value | Binary | Hex | Unsigned | Signed |
|---|---|---|---|---|
| A | 0000 1101 | 0D | 13 | 13 |
| B | 0000 1011 | 0B | 11 | 11 |
| Result | 0001 1000 | 18 | 24 | 24 |
Write the inputs as 8-bit patterns
A = 13 → 0000 1101; B = 11 → 0000 1011. Shorter inputs are padded with zeros on the left.
Add column by column
Starting from the right, 1 + 1 = 10 in binary: write 0 and carry 1. 0000 1101 + 0000 1011 = 0001 1000. The carries out of each column were 0000 1111.
Read the result
The top bit is 0, so the pattern means 24 whether it is read as signed or unsigned.
Type values in binary, octal, decimal or hex and pick an 8, 16, 32 or 64-bit word. Negative numbers use two’s complement, , and overflow is flagged.
Two’s complement
Plain-text formula: −x ≡ NOT x + 1;(mod ;2^w), value = −b_(w − 1)2^(w − 1) + ∑_{i = 0}^(w − 2) b_i2^i
In a w-bit word the top bit counts as −2^(w−1) instead of +2^(w−1). To negate a number, invert every bit and add 1. The same adder then handles positive and negative numbers.
Ranges of a w-bit word
Plain-text formula: unsigned: 0 to 2^w − 1, signed: − 2^(w − 1) to 2^(w − 1) − 1
For 8 bits that is 0 to 255 unsigned and −128 to 127 signed. For 32 bits it is −2,147,483,648 to 2,147,483,647 signed.
Shifts
Plain-text formula: x≪n = x · 2^n mod 2^w, x≫n = ⌊x/2^n⌋
A logical right shift fills with zeros, which divides an unsigned number. An arithmetic right shift copies the sign bit, which divides a signed number and rounds toward minus infinity.
The same bit pattern can mean two numbers. 1111 1011 is 251 unsigned and −5 signed. The hardware stores identical bits; only the instructions that read them differ. Addition, subtraction, the low bits of a product, AND, OR, XOR and left shifts give the same bits either way. Division, right shifts, comparisons and overflow depend on the reading.
Overflow means the true result needs more bits than the word has. Unsigned overflow shows up as a carry out of the top bit, or a borrow when subtracting. Signed overflow happens when two numbers of the same sign give a result of the other sign, such as 127 + 1 = −128 in 8 bits. Many languages wrap silently, so these warnings point to real bugs.
Bits and bytes also size files and memory. Storage uses powers of 10 (1 GB = 10⁹ bytes) and powers of 2 (1 GiB = 2³⁰ bytes), which is why a drive shows less space than its label: see the gigabytes to gibibytes converter.
Binary addition works like decimal addition, column by column from the right, with only four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1). The carry moves one column left, just as a carry of ten does in decimal.
For example, 1101 + 1011 is 13 + 11. The table shows each column, starting from the right. The answer is 11000, which is 24. Adding 1 + 1 + 1 + 1 gives 100, the binary form of 4. To use this page as a binary addition calculator, choose A + B: the steps list the carry out of every column.
| Column (from right) | Bits added | Sum | Write | Carry |
|---|---|---|---|---|
| 1st (1s) | 1 + 1 | 10 | 0 | 1 |
| 2nd (2s) | 0 + 1 + carry 1 | 10 | 0 | 1 |
| 3rd (4s) | 1 + 0 + carry 1 | 10 | 0 | 1 |
| 4th (8s) | 1 + 1 + carry 1 | 11 | 1 | 1 |
| 5th (16s) | carry 1 | 1 | 1 | 0 |
Binary subtraction works column by column from the right. The rules are 0 − 0 = 0, 1 − 0 = 1, 1 − 1 = 0 and 0 − 1 = 1 with a borrow from the next column. A borrow turns the 0 into 10, which is 2, and the column you borrowed from loses 1.
For example, 1101 − 0110 (13 − 6): the 1s column gives 1 − 0 = 1. The 2s column needs a borrow: 10 − 1 = 1. The 4s column now holds 0, so it borrows too: 10 − 1 = 1. The 8s column is left with 0 − 0 = 0. The answer is 0111, which is 7.
Computers subtract a different way: they add the two’s complement of B. Invert every bit of B, add 1, then add the result to A and drop any carry out of the top bit. Choose A − B in the calculator to see the borrows and this check step by step.
To multiply, write a copy of A for every 1 bit in B, shifted left by that bit’s position, then add the copies. For 101 × 11 (5 × 3), the copies are 101 and 1010, and 101 + 1010 = 1111, which is 15. Shifting left by one place always doubles a number.
Binary long division follows the decimal method, but each quotient digit is 0 or 1: the divisor either fits under the current part of the dividend or it does not. For 1101 ÷ 101 (13 ÷ 5) the quotient is 10 and the remainder is 11, that is 2 remainder 3. Choose A ÷ B to get the quotient and remainder in every base.
Each binary digit is worth twice the digit to its right. To read a binary number in decimal, add the place values where the bit is 1. For example, 0010 1101 = 32 + 8 + 4 + 1 = 45, and 1111 1111 = 255, the largest 8-bit unsigned number.
To convert decimal to binary, divide by 2 repeatedly and write down the remainders, then read them from the last to the first. For 45: 45 ÷ 2 = 22 r 1, 22 ÷ 2 = 11 r 0, 11 ÷ 2 = 5 r 1, 5 ÷ 2 = 2 r 1, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1. Reading upward gives 101101. For bases from 2 to 36 and fractions, use the number base converter.
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| 45 in binary | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 255 in binary | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Write the number with the full word size, invert every bit, then add 1. In 4 bits, the two’s complement of 0001 is 1110 + 1 = 1111, so 1111 means −1. In 8 bits, 1111 1111 is −1 as a signed number and 255 as an unsigned one.
To read a signed pattern whose top bit is 1, take its two’s complement and put a minus sign in front. For 1001 0110: invert to 0110 1001, add 1 to get 0110 1010 = 106, so the pattern means −106. Subtracting 256 from its unsigned value, 150, gives the same answer.
| Bits | Unsigned | Signed (two’s complement) |
|---|---|---|
| 0000 0000 | 0 | 0 |
| 0111 1111 | 127 | 127 (signed maximum) |
| 1000 0000 | 128 | −128 (signed minimum) |
| 1001 0110 | 150 | −106 |
| 1111 1011 | 251 | −5 |
| 1111 1111 | 255 | −1 |
A bitwise calculator compares two numbers one bit position at a time, with no carries between columns. AND keeps a bit only where both inputs have a 1, so it is used to mask bits off. OR sets a bit where either input has a 1. XOR sets a bit where the inputs differ, so applying the same XOR twice gives back the original. NOT flips every bit.
For example, in hex F0F0 AND 0FF0 = 00F0: only the middle four bits are 1 in both. Shifts move the whole pattern: a left shift by n multiplies by 2ⁿ, and a right shift by n divides by 2ⁿ.
| A | B | A AND B | A OR B | A XOR B | NOT A |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 | 0 |
Compute 100 + 80 in an 8-bit word and check for overflow.
Answer: 100 + 80 = 1011 0100 in 8 bits: correct as an unsigned result (180), but a signed overflow that wraps to −76.
Add column by column from the right, as in decimal, using 0 + 0 = 0, 0 + 1 = 1 and 1 + 1 = 10 (write 0, carry 1). With a carry, 1 + 1 + 1 = 11. For example 1101 + 1011 = 11000, which is 13 + 11 = 24.
100. Four is 1 × 4 + 0 × 2 + 0 × 1, so it needs three binary digits. Step by step: 1 + 1 = 10, 10 + 1 = 11, and 11 + 1 = 100.
As an unsigned number, 1111 1111 is 255 (128 + 64 + 32 + 16 + 8 + 4 + 2 + 1), the largest value 8 bits can hold. As a signed 8-bit number in two’s complement, it is −1.
It is the standard way computers store negative integers. To negate a number, invert all its bits and add 1. For 5 = 0000 0101, inverting gives 1111 1010 and adding 1 gives 1111 1011, which is −5 in 8 bits (and 251 if read as unsigned).
Unsigned, a w-bit word holds 0 to : 255 in 8 bits, 65,535 in 16 bits, 4,294,967,295 in 32 bits and 18,446,744,073,709,551,615 in 64 bits. Signed (two’s complement), the range is to , such as −128 to 127 in 8 bits and −32,768 to 32,767 in 16 bits. Larger inputs are rejected; pick a wider word.
A logical shift fills the empty top bits with 0. An arithmetic shift copies the sign bit. In 8 bits, −16 = 1111 0000 shifted right by 2 is 1111 1100 = −4 arithmetically, but 0011 1100 = 60 logically.
NOT flips every bit, and in two’s complement that always gives −x − 1. NOT 0000 0101 = 1111 1010, which is −6 as a signed 8-bit number (and 250 unsigned).
127 = 0111 1111, and adding 1 gives 1000 0000. Unsigned, that is 128 and fine. Signed, it is −128, the most negative 8-bit value: the result wrapped around. Pick a larger word size, such as 16 bits, to get 128.
Decimal to binary with each division by 2, padding to 8–64 bits, two’s complement and fractions.
Hex to decimal with place-value steps, plus binary, octal and any base 2 to 36, fractions included.
Binary to decimal with each bit’s power of 2 and a running total, signed or unsigned, fractions included.
a mod n with steps, negative numbers, power mod and modular inverses.
LCM and GCF of up to 10 numbers with steps: multiples, prime factors, Euclid’s algorithm and a coprime check.
Type or tap expressions with exact fractions, memory, variables, constants and complex mode.
Learn more: For hex, octal and binary input, and bitwise AND, OR and XOR in the full calculator, read base-n and bitwise operations.
Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?