Fundamentals 12 min read

Why Computers Use Two’s Complement: Understanding Original, One’s and Two’s Complement

This article explains machine numbers, true values, and the concepts of original code, one's complement, and two's complement, showing why computers adopt complement representations to simplify arithmetic and extend the range of signed integers.

Open Source Linux
Open Source Linux
Open Source Linux
Why Computers Use Two’s Complement: Understanding Original, One’s and Two’s Complement

1. Machine Numbers and True Values

Before learning about original code, one's complement, and two's complement, we need to understand the concepts of machine numbers and true values.

1.1 Machine Number

A machine number is the binary representation of a number stored in a computer, using the most‑significant bit as the sign (0 for positive, 1 for negative). For an 8‑bit word, +3 is 00000011 and –3 is 10000011.

1.2 True Value

Because the sign bit is part of the representation, the numeric value of a signed machine number is not the same as its raw binary value. For example, 10000011 represents –3, not 131.

Example: 00000001 has true value +1; 10000001 has true value –1.

2. Original Code, One’s Complement, Two’s Complement

These are three encoding schemes used by computers to store signed integers.

2.1 Original Code

The original code (sign‑magnitude) stores the sign in the most‑significant bit and the magnitude in the remaining bits. For 8‑bit numbers:

[+1] original = 00000001 [-1] original = 10000001

The range is –127 to +127.

2.2 One’s Complement

Positive numbers keep the same pattern; negative numbers invert all bits except the sign bit.

[+1] = 00000001 (original) → 00000001 (one’s complement) [-1] = 10000001 (original) → 11111110 (one’s complement)

One’s complement makes it difficult to recognise negative values directly, so conversion to original code is usually required.

2.3 Two’s Complement

Positive numbers remain unchanged; for negatives, invert all bits except the sign bit and add 1 (i.e., one’s complement plus 1).

[+1] = 00000001 (original) → 00000001 (two’s complement) [-1] = 10000001 (original) → 11111111 (two’s complement)

Two’s complement also eliminates the separate representation of –0 and allows the range –128 to +127 for an 8‑bit word.

3. Why Use One’s and Two’s Complement?

Using only original code for subtraction leads to incorrect results because the sign bit participates in arithmetic. One’s complement fixes subtraction but introduces a signed zero. Two’s complement resolves both issues, enabling the computer to perform subtraction using only addition.

For a 32‑bit signed integer, two’s complement yields the range –2³¹ to 2³¹‑1.

4. Deeper Insight: Modular Arithmetic

The trick of letting the sign bit participate in addition is equivalent to performing arithmetic modulo 2ⁿ, where n is the word length. This is analogous to a clock face where moving backward is the same as moving forward the complementary number of steps.

Two’s complement of –x is congruent to (2ⁿ – x) modulo 2ⁿ, which explains why adding a negative number can be replaced by adding its positive modular equivalent.

Example images illustrate the modular definition of the remainder operation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

binary representationdigital logiccomputer fundamentalstwo's-complementnumber systems
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.