banner
指数爆炸

指数爆炸

我做了对饭 !
github
bilibili

What is the true definition of complement?

What is the complement?#

The complement is using positive numbers to represent negative numbers

========================================

Examples#

  1. For example, when representing -1 with an 8-bit binary number, only the complement of 1 (00000001) needs to be obtained. The complement is obtained by flipping each digit of 00000001 from 0 to 1 and 1 to 0, then adding 1 to the complement result, finally converting it to -1 (11111111)

  1. Another example, to represent -5, the binary number for 5 is 0101, flipping 0101 and adding 1, it is converted to 1011 (-5)

=======================================

  • Actually, you really don't need to worry about what the teacher taught you:
    The original, inverse, and complement of positive numbers are the same, while for negative numbers, the inverse and complement need to be calculated.
    Also, everything stored in the computer is in complement form, not in original form.

Actually, the computer stores these numbers in this way, just using the complement to represent negative numbers.

=======================================

So why use the complement to represent negative numbers?#

Because all decimal calculations in the computer are binary operations, and all subtractions are additions in the computer. If not using the complement, then 1-1 would equal -2. For example,
0001-------------(1)
1001-------------(-1)
0001+1001=
1010-------------(-2)
So we use the complement to represent negative numbers
0001-------------(1)
1111-------------(-1)
0001+1111=
10000------0000-------(0)

=======================================

Why is it called the complement?#

Perhaps because when a number is added to its complement, the result is 0. Actually, think about it, when representing -5, it is represented using 5, so -5 and 5 are opposite numbers.

=======================================

Quick tip:#

Since a number and its complement are opposite numbers, complement--->flip+1--->convert to the original number.
-5 (1011)------flip+1-------5 (0101)

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.