Binary Calculator
Add or subtract binary numbers with results in binary and decimal.
Back to all tools on ToolForge
Binary A
Binary B
Result
Binary:
Decimal:
About Binary Calculator
This binary calculator performs addition and subtraction on binary numbers, showing results in both binary and decimal formats for verification and learning.
Binary Addition Fundamentals
Binary addition operates on two digits (0 and 1) with carry propagation:
| A | B | Sum | Carry Out |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 |
Binary Addition Example with Carry
1011 (11 in decimal) + 0101 (5 in decimal) ------ 10000 (16 in decimal) Column-by-column (right to left): Column 0: 1 + 1 = 0, carry 1 Column 1: 1 + 0 + 1(carry) = 0, carry 1 Column 2: 0 + 1 + 1(carry) = 0, carry 1 Column 3: 1 + 0 + 1(carry) = 0, carry 1 Column 4: 1(carry) = 1 Final result: 10000
Binary Subtraction Fundamentals
Binary subtraction uses borrowing when the minuend is smaller than the subtrahend:
| A | B | Difference | Borrow |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
Binary Subtraction Example with Borrowing
1010 (10 in decimal)
- 0011 (3 in decimal)
------
0111 (7 in decimal)
Column-by-column (right to left):
Column 0: 0 - 1 = need to borrow → 10 - 1 = 1, borrow 1
Column 1: 0 - 1(borrowed) - 1 = need to borrow → 10 - 1 - 1 = 0, borrow 1
Actually: after first borrow, position 1 becomes 0, so 0-1 needs borrow again
Result: 1 (borrow chain continues)
Column 2: After borrow chain: 1 - 0 = 1
Column 3: 1 - 0 = 1 (but was borrowed, so 0)
Simplified view:
1010 = 8 + 2 = 10
0011 = 2 + 1 = 3
10 - 3 = 7 = 0111
Decimal to Binary Reference
| Decimal | Binary | Hex |
|---|---|---|
| 0 | 0 | 0x0 |
| 1 | 1 | 0x1 |
| 2 | 10 | 0x2 |
| 3 | 11 | 0x3 |
| 4 | 100 | 0x4 |
| 7 | 111 | 0x7 |
| 8 | 1000 | 0x8 |
| 15 | 1111 | 0xF |
| 16 | 10000 | 0x10 |
| 31 | 11111 | 0x1F |
| 32 | 100000 | 0x20 |
| 64 | 1000000 | 0x40 |
| 127 | 1111111 | 0x7F |
| 128 | 10000000 | 0x80 |
| 255 | 11111111 | 0xFF |
Two's Complement (Negative Numbers)
Computers represent signed integers using two's complement notation:
- Positive numbers: Standard binary representation
- Negative numbers: Invert all bits of the positive value, then add 1
- Zero: All bits are 0 (only one representation, unlike sign-magnitude)
Example: Representing -5 in 8-bit two's complement Step 1: +5 in binary = 00000101 Step 2: Invert bits = 11111010 Step 3: Add 1 = 11111011 Result: -5 = 11111011 Verification using addition: 11111011 (-5) + 00000101 (+5) ----------- 100000000 = 256 (overflow ignored) = 0 ✓ Range of 8-bit two's complement: -128 to +127 Range of 16-bit two's complement: -32768 to +32767 Range of 32-bit two's complement: -2147483648 to +2147483647
Binary Arithmetic in Computing
- ALU Operations: Arithmetic Logic Units perform binary addition/subtraction at hardware speed
- Address Calculation: Memory addresses are computed using binary arithmetic
- CRC and Checksums: Error detection uses binary polynomial arithmetic
- Cryptography: Encryption algorithms rely on binary XOR and modular arithmetic
- Digital Signal Processing: DSP operations use fixed-point binary math
- Graphics: Pixel blending and transformations use binary arithmetic
Overflow and Underflow
Fixed-width binary arithmetic has limits:
- Overflow: Result exceeds maximum representable value (e.g., 255 + 1 = 0 in 8-bit)
- Underflow: Result is below minimum representable value (e.g., 0 - 1 = 255 in unsigned 8-bit)
- Detection: Processors set overflow flags to signal these conditions
8-bit Unsigned Overflow Example: 11111111 (255) + 00000001 (1) ----------- 100000000 (256 - requires 9 bits) ^^^^^^^^ Only 8 bits stored: 00000000 = 0 (overflow!) 8-bit Signed Overflow Example: 01111111 (127, maximum positive) + 00000001 (1) ----------- 10000000 (-128, minimum negative - wrong sign!)
How to Use Binary Calculator
- Enter binary A: Type the first binary number using only 0 and 1 digits.
- Enter binary B: Type the second binary number.
- Choose operation: Click "Add" for addition or "Subtract" for subtraction.
- View results: See the result displayed in both binary and decimal formats.
Tips
- Only use digits 0 and 1 - other characters will cause parsing errors
- Leading zeros are optional and ignored (0011 = 11)
- Use the decimal output to verify your binary calculations
- For subtraction resulting in negative numbers, the decimal result shows the signed value
Frequently Asked Questions
- How does binary addition work?
- Binary addition uses four rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 (write 0, carry 1). When adding column by column from right to left, carry values propagate to the next position. Example: 1011 + 0101 = 10000 (11 + 5 = 16 in decimal).
- How does binary subtraction work?
- Binary subtraction uses borrowing: 0-0=0, 1-0=1, 1-1=0, 0-1=1 (borrow from left). When the top bit is 0 and you need to subtract 1, borrow from the next position (which gives you 2 in binary, i.e., 10). Example: 1010 - 0011 = 0111 (10 - 3 = 7).
- What is two's complement notation?
- Two's complement represents negative numbers in binary. To negate a number: invert all bits (0→1, 1→0), then add 1. For example, -5 in 8-bit = ~00000101 + 1 = 11111011. This system allows subtraction to be performed using addition circuitry.
- Why do computers use binary?
- Computers use binary because digital circuits have two stable states representing 0 and 1 (off/on, low/high voltage). Binary is reliable, noise-resistant, and maps directly to Boolean logic. All data and instructions are ultimately represented as binary in computer memory and processors.
- How do I verify binary calculations?
- Convert operands to decimal, perform the operation, then convert the result back to binary. For example: 1011 + 0101 → (11 + 5 = 16) → 10000. This cross-verification helps catch errors when learning binary arithmetic or debugging digital logic designs.
- What is binary overflow?
- Overflow occurs when a calculation produces a result larger than the available bits can represent. In 8-bit arithmetic, adding 255 + 1 produces 256, which requires 9 bits. The 9th bit is lost, resulting in 0 (wraparound). Overflow detection is critical in computer arithmetic.