Skip to main content
math

Two's Complement Calculator

Convert between signed integers and their two's complement binary representation. Supports 8, 16, and 32-bit widths.

By Christopher FloiedPublished Updated

Results

Two's Complement Binary

1e+7

Decimal Value

-42

Hexadecimal

D6

How to Use This Calculator

1

Enter your input values

Fill in all required input fields for the Two's Complement Calculator. Follow the units and input format printed next to each field. Where a unit selector is available, choose the units that match your data.

2

Review your inputs

Double-check that all values are correct and match the units or format shown for each field. Incorrect units are the most common source of calculation errors and can produce results that are off by factors of 2, 10, or more.

3

Read the results

The Two's Complement Calculator computes the output in your browser and displays the results, with units clearly labeled, as soon as they are ready — no data sent to a server.

4

Explore parameter sensitivity

Try adjusting individual input values to see how the output changes. This is a quick and effective way to develop intuition about how different parameters influence the result and to identify which inputs have the largest effect.

When to Use This Calculator

  • •Use the Two's Complement Calculator when you need a quick mathematical result without writing out all the steps manually, saving time on repetitive calculations.
  • •Use it to verify hand calculations on tests or assignments and catch arithmetic mistakes.
  • •Use it when teaching or explaining mathematical concepts to others, demonstrating how changing inputs affects the result.
  • •Use it to explore the behavior of mathematical functions across a range of inputs.

Related Calculators

About Two's Complement Calculator

Two's complement is the standard way computers represent signed integers. In this system, positive numbers are stored normally in binary, while negative numbers are represented by inverting all bits and adding 1. The key advantage is that addition and subtraction use the same hardware circuit regardless of sign — the processor does not need separate logic for signed arithmetic. The most significant bit (MSB) serves as the sign bit: 0 for positive, 1 for negative. For n bits, the range is −2^(n−1) to 2^(n−1)−1. For example, 8-bit two's complement represents −128 to 127. This calculator converts any signed integer to its two's complement representation at your chosen bit width.

The Math Behind It

Two's complement of a negative number −n in w bits is 2^w − n. Shortcut: invert all bits (one's complement) and add 1. Properties: there is one representation of zero (all 0s), the MSB is the sign bit, and the most negative number (−2^(w−1), e.g., −128 for 8 bits) has no positive counterpart. Addition: A + B mod 2^w gives the correct signed result if no overflow. Overflow detection: if adding two positives gives negative, or two negatives gives positive, overflow occurred. Sign extension: to convert to a wider representation, replicate the MSB. Negation: −x = ~x + 1. This scheme was chosen over sign-magnitude and one's complement because it has a unique zero and simplifies adder design.

Formula Reference

Two's Complement (negative)

−n → 2^w − n (for w-bit representation)

Variables: w = bit width, n = absolute value

Two's Complement (shortcut)

Invert all bits of |n|, then add 1

Variables: Equivalent to 2^w − n

Range

−2^(w−1) to 2^(w−1) − 1

Variables: 8-bit: −128 to 127

Worked Examples

Example 1: Find 8-bit Two's Complement of −42

Represent −42 in 8-bit two's complement.

Step 1:42 in binary = 00101010
Step 2:Invert all bits: 11010101
Step 3:Add 1: 11010101 + 1 = 11010110

−42 in 8-bit two's complement = 11010110₂ = D6₁₆

Common Mistakes & Tips

  • !Forgetting to add 1 after inverting — one's complement is NOT two's complement.
  • !Not specifying bit width — −1 is 11111111 in 8 bits but 1111111111111111 in 16 bits.
  • !Confusing sign-magnitude with two's complement representation.
  • !Not checking for overflow when the result exceeds the representable range.

Related Concepts

Used in These Calculators

Calculators that build on or apply the concepts from this page:

Frequently Asked Questions

Why is two's complement preferred over sign-magnitude?

Two's complement has only one representation of zero (sign-magnitude has +0 and −0), and addition works the same for positive and negative numbers, simplifying hardware.

What is the range of an n-bit two's complement number?

From −2^(n−1) to 2^(n−1) − 1. For 8 bits: −128 to 127. For 16 bits: −32768 to 32767. For 32 bits: −2,147,483,648 to 2,147,483,647.

Add the live Two's Complement Calculator to your site. Free to embed, with a link back to MegaCalc.