C language source code, complement, and code you don't care about the origin

Source: Internet
Author: User
======================1. Prepare knowledge. ==================
Note: the ' = = ' here is the equal meaning. ' = ' is the meaning of the assignment.
In the Machine world:
The highest digit of a positive number is the sign bit 0, and the highest digit of the negative number is the sign bit 1.
For positive numbers: anti-code = = Complement = = Original code.
For negative numbers: anti-code = = In addition to the symbol bit, you take the counter.
complement = = +1 counter code.
Original Code = = complement-1 of the inverse code = = Complement Code +1. (after reading this article, should be able to intuitively realize the correctness of this type)

The following rules can be easily found:
Natural calculation: A-b==c.
Computer calculation: A-b==a+b's complement ==d.
The complement of C is D.
By this method, the subtraction operation can be converted to an additive operation.

So the complement is designed to:
1. The symbolic potential energy with the valid value part of the operation, thus simplifying the operation rules.
2. Reduce operation conversion to add operations, further simplifying the computer circuit design of the operator.

=====================2. The origin of inspiration. =================

Concept definition:

The first kind of understanding: Remember the Junior high school mathematics "supplementary angle" concept.
When the sum of two numbers equals 100, these two numbers are called "complements" and 100 are called "numbers".
If b+c==100, then
a-b==a-(100-c) ==a+c-100.
To be sure: the complement of a-b=a+b-number.

The second kind of understanding:
The concept of the model, to the clock for example 0-12 model 13 The current clock is 10, you want to adjust to 4, you can adjust the 6 hours forward, you can also adjust 6 hours
That is, 10-6 = 4 can be expressed by 10+6 = 12+4.
The complement principle is the same
1 bytes is a 8-bit binary
Which means that the model is 128, 65 can be expressed in +63 to introduce this method into the machine world:
Set INT is a 8-bit integer (the highest bit is the symbol bit), and the number H is 9 bits: 1 0000 0000.
A,b is any two int.
Obviously, the a+a's complement ==h,h overflow the highest bit, leaving the int value 0.
①. Enter A-b,
②. The machine will be a-b and fed to the adder: (A's complement) + (-B's complement), it equals C.
Don't forget, C is a complement.
③. Output: C's original code.

After assigning a value a=a,b=b, compare:
a-b== (A's complement) + (-B's complement) ==c.//here C is the complement form.
A-b==a+b complement-number ==c.//here C is the number, which can be considered as the original code form.
if (c>=0) the original code of the C==c==c; (' = = ' is equal meaning, not assigned)
else c==c the original code;

This "complement" in the "complement", with the early secondary school that "fill" is a meaning.

The concept of mathematics in the name is really not defined casually, such as "mathematical logic", so the name of righteousness is: "Mathematical language" to clarify the "logic."


Go from: http://www.tianyablog.com/blogger/post_show.asp?blogid=227218&postid=7046448

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.