Skip to main content
HexConverter

Two's Complement Explained: Signed Math in Hex & Binary

Learn how computers store and compute negative numbers in binary and hexadecimal. Master bit inversion, adding one, sign extension, and bit-width limits (8, 16, 32, and 64 bits).

1. Why Computers Use Two's Complement

In early computer engineering, pioneers experimented with various ways to represent negative numbers, including "sign-magnitude" (a dedicated sign bit) and "one's complement" (inverting all bits). However, both systems had serious flaws: they suffered from having two separate zeros (+0 and -0) and required complex, slow decision logic in hardware circuits.

Two's complement solved both problems elegantly. In two's complement:

  • There is exactly one zero (0x00).
  • Addition and subtraction use the exact same electronic adder circuits without modification.
  • The most significant bit (MSB) cleanly indicates sign: 0 for positive, 1 for negative.

2. The Two-Step Negation Algorithm

To find the negative representation of any integer:

  1. Step 1 (Invert): Flip every bit from 0 to 1 and from 1 to 0 (bitwise NOT).
  2. Step 2 (Add 1): Add 1 to the inverted binary number, ignoring any final carry out past the register bit width.
Example: Negating +5 in an 8-bit register
Positive 5 in binary: 0000 0101
Invert all bits:      1111 1010
Add 1:               1111 1011 → 0xFB in hex (-5 decimal)

3. Signed Integer Ranges Across Bit Widths

Word SizeMinimum NegativeMaximum PositiveHex Representation of -1
8-bit (Byte)-128 (0x80)+127 (0x7F)0xFF
16-bit (Short)-32,768 (0x8000)+32,767 (0x7FFF)0xFFFF
32-bit (Int / Long)-2,147,483,648+2,147,483,6470xFFFFFFFF
64-bit (Quadword)-9,223,372,036,854,775,808+9,223,372,036,854,775,8070xFFFFFFFFFFFFFFFF
Test two's complement live in our calculator

Switch between signed and unsigned interpretations across all bit widths.

Open Converter

Frequently Asked Questions

Direct answers to technical and practical questions regarding this tool and base-16 conversion.

What is two's complement?

Two's complement is the universal mathematical method computers use to represent and calculate signed (positive and negative) integers in binary. In two's complement, the most significant bit (MSB) carries negative weight (e.g. -128 in an 8-bit system). This allows standard addition circuitry to perform subtraction without requiring separate subtraction hardware.

How do you negate a number in two's complement?

The standard algorithm has two steps: (1) Invert all bits (change all 1s to 0s and all 0s to 1s, which is a bitwise NOT operation), and (2) Add 1 to the result.

Why does 0xFF equal -1 in an 8-bit signed integer?

In an 8-bit two's complement system, the MSB has weight -128, while the remaining 7 bits have positive weights summing to 127. When all bits are 1 (11111111 = 0xFF), the calculation is: -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1.

What is the range of numbers an 8-bit signed integer can hold?

An 8-bit two's complement integer ranges from -128 (0x80) to +127 (0x7F). The asymmetry (one more negative number than positive) occurs because 0 is counted among the non-negative numbers.

Related Conversion Tools & Resources

Explore companion converters, bitwise arithmetic calculators, and reference charts.

Sources & Technical References

Technical Verification & Editorial Accountability

Written by Sarah Chen (Embedded Systems Engineer) • Verified by Marcus Brody, PE

Reviewed: 2026-10-02MethodologyEditorial PolicyReport Error