1's & 2's Complement Calculator
Calculate 1's and 2's complement of binary numbers with step-by-step process. Essential for signed binary arithmetic and computer systems.
Complement Calculator
Binary Complements
Binary complements are mathematical operations used to represent negative numbers in binary form. They are fundamental to computer arithmetic and digital system design.
1's Complement
Definition
The 1's complement of a binary number is obtained by inverting all bits - changing every 0 to 1 and every 1 to 0.
Calculation Method
- Take the original binary number
- Invert each bit (0 → 1, 1 → 0)
- The result is the 1's complement
Example: 1's Complement of 1010
- Original: 1010
- Invert: 0101
- Result: 0101 (1's complement)
2's Complement
Definition
The 2's complement is obtained by adding 1 to the 1's complement. It's the standard method for representing signed integers in computers.
Calculation Method
- Calculate the 1's complement
- Add 1 to the result
- The sum is the 2's complement
Example: 2's Complement of 1010
- Original: 1010
- 1's complement: 0101
- Add 1: +0001
- Result: 0110 (2's complement)
Signed Number Representation
Sign-Magnitude
Uses the MSB as sign bit (0=positive, 1=negative). Simple but has two zeros.
1's Complement Representation
Negative numbers are 1's complement of positive. Still has two zeros problem.
2's Complement Representation
Most common method. Negative numbers are 2's complement of positive. Single zero.
Range of Numbers
For n-bit 2's Complement
- Range: -2^(n-1) to +2^(n-1) - 1
- 4-bit: -8 to +7
- 8-bit: -128 to +127
- 16-bit: -32,768 to +32,767
Advantages of 2's Complement
Arithmetic Simplicity
- Addition and subtraction use same circuitry
- No special handling for sign bit
- Overflow detection is straightforward
Unique Zero
- Only one representation for zero
- Eliminates ambiguity in comparisons
- Simplifies hardware design
Applications
Computer Arithmetic
- Integer representation in CPUs
- Signed arithmetic operations
- Memory addressing
- Assembly language programming
Digital Signal Processing
- Audio and video processing
- Filter implementations
- Mathematical computations
- Control systems
Examples & Practice
Example 1: 8-bit Representation of -5
- +5 in binary: 00000101
- 1's complement: 11111010
- Add 1: 11111011
- Result: -5 = 11111011
Example 2: Convert 11110000 to Decimal
- MSB = 1, so it's negative
- 1's complement: 00001111
- Add 1: 00010000
- Decimal: 16, so original = -16
Common Pitfalls
Overflow
Adding two positive numbers that result in a negative, or two negative numbers that result in a positive indicates overflow.
Sign Extension
When extending bit width, copy the sign bit to maintain the same value (e.g., 4-bit 1111 becomes 8-bit 11111111).