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

Source: Internet
Author: User

Before High School, mathematics was like this. 1 + 1 = 2. These are all dead.

After going to college, the world is like this ......

The language with the lowest level of machine language is 0 and 1. These two marks are used for computing.

In the past, all our mathematical operations were performed on the base 10. Computers can only use binary numbers for computation.

 

We all know that 9 uses the machine language 1001 (The hexadecimal conversion is not described in detail)

Before conversion, the number must be a positive integer. If the number is-9, how can this number be expressed in machine language. If it is a decimal number, how is it expressed.

Original code:

+ 9 and-9, isn't it just a different sign? Just give a single bit more, just sign it.

+ 9 indicates 00001001

-9 indicates 00011001

We can use the binary number to deal with known problems. It is nothing more than encoding and rules.

Then, people refer to this representation with a signed bit as the original code.

 

In a computer, only one addition can be directly calculated.

Example: 9 + 11 = 20

1001 plus 1011 = 1 0100

If the original code is used for calculation

That is, 00001001 + 00001011 = 01 0100

 

This operation is an addition between positive integers, if there is a decimal or negative number between the numbers. What should we do?

Note: The following code is an underscore.

 

Anti-code:

We all know that addition containing negative numbers is actually called subtraction. So what we need to deal with is how to add the negative number to the addition operation just now.

9-3 = 6 rewrite to 9 + (-3) = 6

Use the original code for calculation: 00001001 + 00010011 = 11100 =-12

 

This result is obviously incorrect.

Then how did this problem come about? This problem is caused by calculating the symbol bit in the original code, which leads to incorrect results.

 

Since the result is incorrect, you can edit it. Find a correct rule. You cannot start a name.

First, to be correct, you must calculate the symbol bit.

First, when two numbers are computed, the string after the symbol bit represents the absolute value of the real value.

 

Example

Before completing the code, let's take an example.

In real life, at a certain time point, you can watch the clock. After that, you have been active for nine hours. What time is it?

 

First, let's explain how normal people calculate it. Normal people must be: 9 + 9-12 = 6 well, now.

Another algorithm is. You know that 12 hours is a lap. After nine hours, we can calculate as follows: 9-(12-9) = 6 is also 6 points.

 

Let's take a look at the above example:

+ 9 + (-3)

00001001 + 00010011

 

If the original code is used for calculation, the result is definitely incorrect. Not considered for the moment before the symbol bit

I will convert the negative original code to 1100.

After calculation: 00001001 + 00011100 = 0010The 0101 symbol bit has changed. The value must be 21. But 21> 15 = 2 ^ 4-1 affects the symbol bit. Calculate the number of changes from 3 to 12. Therefore, the result is 21-15 = + 6.

 

Prior to this, the symbol bit is not considered. If the symbol bit is not considered, all symbols after the symbol bit are reversed by bit. Change 0 to 1, 1, and 0.

This form of encoding is called an anti-code.

 

In this way, the computer can calculate the subtraction of binary.

 

Complement

In the subtraction operation above, the calculation result can be obtained. But did you find it. The value 6 is not displayed in the result.

To solve the problem above. During the conversion from-3 to + 12, the value is changed by 15. However, the effect of 15 is not equivalent to 12 hours in the clock operation. So we need to perform the back code + 1 before the calculation.

That is, the complement of-3 = reverse code + 1 = 00011100 + 1 = 00011101

 

Calculation after: 00001001 + 00011101 = 00101010 value + 6

Symbol bit. the even number is still positive.

 

Now I understand what it is called a supplementary code. Do you still remember what it is? This is just like that.

The complement is based on the original code, finding the one that exactly complements him to form a number of symbol bits.

The simplest way to get it is: original code-> reverse code and then + 1

 

Floating Point Number

In computer operations, decimal operations must also be processed. That is, the so-called floating point number.

A classmate asked me how the question was 0.1 + 0.1 = 1. This is obviously a pitfall. The use of people's existing decimal ideas makes it hard to figure out.

Before learning about this problem, let's first talk about how to define it in decimal places.

What does 0.1 0.01 represent.

In decimal, the weights of each position are different.

For example, 1 in 100 represents 10 ^ 2.

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

 

Similarly, each decimal value has its own weight. So it is in the binary value. Each number has its own weight.

0.1 is obviously 2 ^-1. So 0.1 + 0.1 ...... Your world view has not been destroyed ......

 

As for floating-point calculation, I will not be embarrassed. The floating point operation adds the point limit to the computer. In fact, it is all encoded by itself through 0 and 1. To put it bluntly, it's just making code and creating rules. And then pass. .

 

Summary:

1. Read the book and see the formula. Maybe a few questions will all be done, those formulas. Haha ......

2. There is no absolute correctness. It's just that you haven't touched that circle.

3. If you cannot understand the book, you can start to compile it. After you compile the program, you can go back and see it. Suddenly, it seems that the compilation is quite right ......

 

Before writing this blog, I did not know what the anti-code is for. I only knew how to get the anti-code. In the process of writing, think twice. What is the use of reverse code? Why? Cannot understand ...... First, write ...... And write them all.

If there are any errors in the article, please make sure that you are correct.

 

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

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.