Two’s Complement Calculator
Convert between decimal and two’s complement binary with a fixed bit width.
Twos Complement Calculator
Convert between decimal and twos complement binary representation with step-by-step explanations
Input & Settings
Calculate twos complement by flipping bits and adding 1
Result
Calculation output and explanation
Twos Complement Information
How Twos Complement Works
- • Positive numbers: same as binary representation
- • Negative numbers: flip all bits and add 1
- • Range for n bits: -2^(n-1) to +(2^(n-1) - 1)
- • Only one representation for zero
- • Standard in modern computer systems
Example (4-bit)
How it works
Two’s complement is the usual way CPUs store signed integers. Positive values look like ordinary binary. Negatives: invert all bits (ones’ complement), then add 1. The MSB is the sign bit (1 = negative). Zero has one encoding: all zeros.
n-bit range is −2ⁿ⁻¹ … 2ⁿ⁻¹−1 (one more negative than positive). Example 4-bit: −8 … +7.
Why it stuck
- Same adder hardware for signed and unsigned (mod 2ⁿ)
- Single zero—no +0/−0 mess like sign-magnitude
- Negate by ~x + 1
Overflow wraps: INT_MAX + 1 becomes INT_MIN on typical wraparound. In C/C++, signed overflow is undefined behavior—do not rely on wrap for portable code.
Quick 8-bit example
Related tools
Frequently Asked Questions
Vs ones’ complement?
Ones’ complement only flips bits and has two zeros. Two’s adds one more step and is what nearly all modern ISAs use for integers.
Why does bit width matter?
The same pattern means different values at different widths. 1111 is −1 in 4-bit two’s complement, not −1 as an 8-bit value unless you sign-extend.
Arithmetic right shift?
Fills with the sign bit so negatives stay negative when dividing by two (toward −∞ in typical two’s implementations—check your language).
Related tools
Related tools
Related Number Tools
Add/Subtract Percentage
Add or subtract percentages from numbers
Age Calculator
Calculate age from birth date
Angle Converter
Convert between angle units
Area Converter
Convert between area units
Armstrong Number Checker
Check if a number is an Armstrong number
Average Calculator
Calculate average of numbers
Binary ↔ Decimal Converter
Convert between binary and decimal
BMI Calculator
Calculate your Body Mass Index (BMI) using metric or imperial units. Get instant health category classification and personalized weight range recommendations.
Box Plot Generator
Generate box plots from data
Combinations Calculator
Calculate combinations