Two Complement Calculator
Work out two complement instantly with clear inputs, formula shown and shareable results.
About Two Complement Calculator
Two's complement stores a negative value as 2^w + v, so subtraction becomes ordinary addition and there is a single representation of zero. The top bit acts as the sign bit.
Formula
Two's complement
for v < 0 the stored pattern is 2^w + v; range is −2^(w−1) to 2^(w−1) − 1
Worked example
With the default values below, Two Complement Calculator returns Two's complement bit pattern of 11010110. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Signed decimal value
- -42
- Register width in bitsaccepts 2–32
- 8
Results
- Two's complement bit pattern
- 11010110
- Same bits read as unsigned
- 214
- One's complement for comparison
- 11010101
- Representable range
- -128 to 127
Step by step
- 1Values used
- 2Two's complement
- 3Two's complement bit pattern= 11010110
- 4Same bits read as unsigned= 214
- 5One's complement for comparison= 11010101
- 6Representable range= -128 to 127
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
How is −42 stored in 8 bits?
256 − 42 = 214, which is 11010110.
Why prefer it to sign-and-magnitude?
It avoids a negative zero and lets the same adder circuit handle both signed and unsigned arithmetic.
Related Calculators
You might also need
- Discrete Logarithm CalculatorAlso in Discrete Math, Logic & Number Theory
- Adjacency Matrix CalculatorAlso in Discrete Math, Logic & Number Theory
- Base 64 Value CalculatorAlso in Discrete Math, Logic & Number Theory
- Bell Number CalculatorAlso in Discrete Math, Logic & Number Theory
- Binary To Decimal CalculatorAlso in Discrete Math, Logic & Number Theory
- Binary To Hexadecimal CalculatorAlso in Discrete Math, Logic & Number Theory
