Two's Complement Calculator

Convert between decimal and binary using two's complement representation for signed numbers

Two's Complement Converter

Range: -128 to 127

Signed integer representation

Only 0 and 1 digits allowed

Example Calculations

Positive Number: 16

Binary: 16 = 10000

8-bit representation: 00010000

Sign bit (MSB): 0 (positive)

Negative Number: -16

1. Start with 16: 00010000

2. Flip bits: 11101111

3. Add 1: 11110000

Result: 11110000 = -16

Two's Complement Process

1

Convert to Binary

Convert the absolute value to binary

2

Invert Bits

Flip all bits (0→1, 1→0)

3

Add One

Add 1 to get final two's complement

Word Size Ranges

BitsMinMax
4-87
8-128127
16-32,76832,767
32-2,147,483,6482,147,483,647

Key Properties

MSB determines sign: 0 = positive, 1 = negative

Unique representation: Each number has exactly one representation

Arithmetic friendly: Addition and subtraction work normally

Asymmetric range: One more negative than positive number

Understanding Two's Complement

What is Two's Complement?

Two's complement is a binary representation system for signed integers where negative numbers are represented by inverting all bits of the positive number and adding 1. This method allows for efficient arithmetic operations and is widely used in computer systems.

Why Use Two's Complement?

  • Unique representation for each number
  • Arithmetic operations work normally
  • No separate circuitry needed for subtraction
  • Widely supported in hardware

Converting Methods

Binary to Decimal (Method 1)

Treat MSB as negative weight:

1011 = -1×2³ + 0×2² + 1×2¹ + 1×2⁰ = -8 + 0 + 2 + 1 = -5

Binary to Decimal (Method 2)

For negative numbers (MSB = 1):

  1. 1. Invert all bits
  2. 2. Add 1
  3. 3. Convert to decimal
  4. 4. Apply negative sign