Skip to main content
Add link to web page
Source Link
Matthias Braun
  • 34.8k
  • 27
  • 158
  • 177

From Donald Knuth's "The Art of Computer Programming" (Volume 2, 3rd edition, pages 203-204):

A two's complement number is complemented with respect to a single power of 2, while a ones' complement number is complemented with respect to a long sequence of 1s.

As an example, we take the four-bit number 0110, decimal 6, and calculate the binary representation of its negative value, -6. We'll use both methods: two's and ones' complement.

Two's complement

We use "a single power of 2", namely 2⁴ (1 0000), to get the two's complement of our example number 0110:

 1 0000 - 0110 -------- 1010 

The "two" in "two's complement" refers to the base of the number (2⁴) from which we subtract our positive number.

See also Wikipedia's Two's complement.

Ones' complement

The "long sequence of 1s" is four ones in our example since our input number 0110 has four bits:

 1111 - 0110 -------- 1001 

The "ones" in "ones' complement" refers to the digits of the number (1111) from which we subtract our positive number.


I've created this page if you want to play around with different ways of representing negative numbers in binary.

From Donald Knuth's "The Art of Computer Programming" (Volume 2, 3rd edition, pages 203-204):

A two's complement number is complemented with respect to a single power of 2, while a ones' complement number is complemented with respect to a long sequence of 1s.

As an example, we take the four-bit number 0110, decimal 6, and calculate the binary representation of its negative value, -6. We'll use both methods: two's and ones' complement.

Two's complement

We use "a single power of 2", namely 2⁴ (1 0000), to get the two's complement of our example number 0110:

 1 0000 - 0110 -------- 1010 

The "two" in "two's complement" refers to the base of the number (2⁴) from which we subtract our positive number.

See also Wikipedia's Two's complement.

Ones' complement

The "long sequence of 1s" is four ones in our example since our input number 0110 has four bits:

 1111 - 0110 -------- 1001 

The "ones" in "ones' complement" refers to the digits of the number (1111) from which we subtract our positive number.

From Donald Knuth's "The Art of Computer Programming" (Volume 2, 3rd edition, pages 203-204):

A two's complement number is complemented with respect to a single power of 2, while a ones' complement number is complemented with respect to a long sequence of 1s.

As an example, we take the four-bit number 0110, decimal 6, and calculate the binary representation of its negative value, -6. We'll use both methods: two's and ones' complement.

Two's complement

We use "a single power of 2", namely 2⁴ (1 0000), to get the two's complement of our example number 0110:

 1 0000 - 0110 -------- 1010 

The "two" in "two's complement" refers to the base of the number (2⁴) from which we subtract our positive number.

See also Wikipedia's Two's complement.

Ones' complement

The "long sequence of 1s" is four ones in our example since our input number 0110 has four bits:

 1111 - 0110 -------- 1001 

The "ones" in "ones' complement" refers to the digits of the number (1111) from which we subtract our positive number.


I've created this page if you want to play around with different ways of representing negative numbers in binary.

Source Link
Matthias Braun
  • 34.8k
  • 27
  • 158
  • 177

From Donald Knuth's "The Art of Computer Programming" (Volume 2, 3rd edition, pages 203-204):

A two's complement number is complemented with respect to a single power of 2, while a ones' complement number is complemented with respect to a long sequence of 1s.

As an example, we take the four-bit number 0110, decimal 6, and calculate the binary representation of its negative value, -6. We'll use both methods: two's and ones' complement.

Two's complement

We use "a single power of 2", namely 2⁴ (1 0000), to get the two's complement of our example number 0110:

 1 0000 - 0110 -------- 1010 

The "two" in "two's complement" refers to the base of the number (2⁴) from which we subtract our positive number.

See also Wikipedia's Two's complement.

Ones' complement

The "long sequence of 1s" is four ones in our example since our input number 0110 has four bits:

 1111 - 0110 -------- 1001 

The "ones" in "ones' complement" refers to the digits of the number (1111) from which we subtract our positive number.