Machine language--code operations (specific explanation of the anti-code complement origin)

Source: Internet
Author: User

before high School, mathematics was this. 1+1=2. these are all dead.

After I went to college. The world is this ...

The language of the lowest level of machine language, there are only two signs 0 and 1. These two flags are the basis for the calculation.

We used to do mathematical operations on the 10 binary. And the computer can only use the binary number to perform the operation.

We all know that 9 machine language is 1001 (the conversion of the binary does not do the specific introduction)

Before conversion. This number, however, is required. This number must be a positive integer. Ability to convert.

Suppose this number is-9. So how does this number be expressed in machine language?

assumed to be decimals. How to express it.

Original code:

+9 and 9, is not a difference between a symbol, give a bit more. You can make a mark.

+9 =0 1001

9 =1 1001

Using binary numbers to deal with our known problems is nothing more than coding, making rules.

Then, it is called the original code of the notation bit.

An operation that can be computed directly in a computer. There is only one addition.

Analogy: 9+11=20

1001+1011=1 0100

Assume. Use the original code to perform the operation

namely:0 1001+0000 1011=01 0100

This operation is an addition between positive integers, assuming that there are decimals, or negative numbers, between the number of operations being performed.

What should be done about it?

Note: The code in the following. The underlined symbol is the bit.

Anti-code:

People know that. Include the addition of negative numbers. is actually the so-called subtraction. So the deal is, how to add negative numbers to the addition operation.

9-3=6 rewritten as + (-3) =6

Operation using the original code representation:0 1001 +0001 0011=11100=-12

The result, obviously, is wrong.

And how did this problem arise? This problem is due to the calculation of the symbol bits in the original code, resulting in incorrect results.

Since the result is not right, then make a compilation. Find a rule that can calculate the right thing anyway. Don't get a name.

First of all. Want to be right. It is necessary to calculate the sign bit.

First of all, the two numbers are counted. The string that follows the sign bit represents the absolute value of the true value.

Complement Introduction Example

Before you say the complement. Let's start with an example.

In real life. A certain moment. It's 9 o ' clock when you look at the clocks.

After that, you have been active for 9 hours. What time is it now?

First of all, how does a normal person count. The normal person must be: 9+9-12=6 Well, now 6 o ' er.

another algorithm, is. You know, 12 hours is a lap. Then the past 9 hours, then can be counted: 9-(12-9) =6 is also 6 points.

Take a look at one of the above examples:

+9 + (-3)

0 1001 +1 0011

Assuming that the original code is used for calculation, the result is not correct. Temporary not considered before the sign bit

I have converted the original code of the negative number. Converted into 1100

After the calculation:0 1001 +1 1100 = 0101 sign bit has changed.

The value should be 21.21>15=2^4-1 so the sign bit is affected.

In your own calculation-3 to 12 of the amount of change. So the result is 21-15=+6.

Before this. The sign bit is not considered.

Symbol bits are not considered. The symbol after the symbol bit is reversed by the bitwise. 0 changed to 1. 1 changed to 0.

This form of encoding is called the inverse code.

This allows the computer to calculate the subtraction of the binary.

Complement

in the subtraction operation above, the result of the operation can be obtained. But the kissing guys found out.

The value 6 is not shown in the results at all.

so in order to solve the above problems.

In the process of converting from 3 to +12, the value changes by 15. But. 15 This numeric effect cannot be equivalent to 12 hours in a clock operation.

Therefore, the inverse code should be +1 before the calculation.

that is-3 of the complement = anti-code +1=0001 1100 +1=0001 1101

After the operation:0 1001+0001 1101=00100110 value is +6

symbol bit, the even number of changes is still positive.

now understand what is called the complement.

Complement, do you remember what is called supplementary angle? This is the same as that, it is a piece of the perfect.

The complement is based on the original code, find that with him exactly complementary, in order to form a sign bit number.

The simplest way to get: The original code-〉 and then +1

Floating point number

in a computer's operation, the operation of decimals is also handled.

That is, the so-called floating point number.

last time a classmate asked me. How 0.1+0.1=1 the question. This is obviously a pit.

Take advantage of the thought of decimal that people have formed. Cause it doesn't make sense.

Before you learn this question, let's start by saying it. In the decimal number of the 10 binary. How to define it.

0.1 0.01 what each represents.

in decimal, each position represents a different weight.

For example, 100 in 1. That's what 10^2 represents.

So, what does 1 in 0.01 represent? Apparently, 1 of this decimal number represents 10^-2.

The same. The decimal number has its own weight in each position. Then in the 2 binary value.

Each number also has its own weight.

0.1 is obviously the 2^-1. So 0.1+0.1 ... Your worldview has not been ruined ...

As for the operation of floating-point numbers, I will not be wordy. The operation of the floating-point number. In the computer, that is, a point limit is added. In fact, all of them are coded by themselves through 0 and 1. To be frank, is to make up the rules. And then the line. just use it.

Summarize:

1. Read a book to see the formula. Don't head big. Maybe do a few questions, all will, those formulas.

Oh......

2, not absolutely correct.

It's just that circle you haven't touched yet.

3, the book can not understand. If you don't understand it, start compiling. When you make up almost the same, and then go back to see, suddenly feel. It seems that the compilation is quite right ...

Before writing this blog, I do not know what anti-code complement is what to use, just know how to get anti-code complement.

In the process of writing, repeat thinking.

What is the use of anti-code complement? Why to introduce? Not clear ... Well, it says first. And then it's all written out .

If there are errors in the article, look at treatise.

Machine language--code operations (specific explanation of the anti-code complement origin)

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.