And binary integer expression

Go back and review it again inside the computer binary integer representation, mainly divided into three categories: original code, anti-code and complement.
Of course, I still have to explain at the beginning, the computer is to complement data storage form.

Original code

The best way to understand this, the "every decade a" decimal me into binary "Every binary one" on the line.
Specifically, how to do it? Or introduce decimal and binary conversion ways.

  • Binary decimal conversion

Man of few words said, directly write the formula, "according to the right to expand the sum":


  • Binary Decimal turn

According to the routine, with the "modulo 2, except in reverse order" approach.
For chestnut: 789 to binary
1. In addition modulo two

Compute remainder Digit
789/2=394 More than 1 10th
394/2=197 More than 0 9th
197/2=98 More than 1 No. 8
98/2=49 More than 0 7th
49/2=24 More than 1 No. 6
24/2=12 More than 0 5th
12/2=6 More than 0 No. 4
6/2=3 More than 0 No. 3
3/2=1 More than 1 The first two
1/2 was 0 More than 1 No. 1

2. The results obtained residue reverse order
789 = 1100010101 (B)
behind the brackets B represents a binary number

  • Why use the computer binary code to represent data

1, technology is simple. The computer is composed of a logic circuit, a logic circuit generally only two states, on and off switches, just "0", "1", respectively.
2, simple rules of operation, and two binary numbers, a combination of product operations simple.
3, for logical operations, binary only two digital, and logical algebra "true", "false" match.
4, easy conversion, binary and decimal conversion simple.
----------- taken from Baidu know

For the original code, I think the understanding of the above on the same subject.

Inverted

As the name suggests, in fact, the anti-code all the bits of the original code, in turn, 1-> 0,0> 1
What's the use? Why do you do that?
Until then, let's answer the following few facts

  • Original code is very difficult to represent negative
    you can see it in many places a negative operational computer? If the integer in the computer are used to represent the original code, negative, how do arithmetic? This will be a very difficult topic. To achieve this effect, the hardware may be required (operator) is designed, and adding a specific recording function computing negative, but in this regard to the hardware design, the problem becomes very troublesome, or if it was designed, the final application to the performance of your computer will be greatly reduced. The introduction of anti-code, it is hoped by another coded form, to solve the problem of negative numbers. Having said that you may wonder why it is still so in turn can represent a negative number, do not worry, I'll gradually solve your problem, first read on.
  • Maximum four binary integer representation of potential energy

You may feel 1111 (B) is the greatest, according to the method described in our previous original code where it is converted to decimal:
1111 (B) = 15
The question is, if we want to represent negative it? So we need to take bit to represent positive and negative, that is, first and provisions 0 positive, 1 negative (in fact, this provision can not be said that it is amazing, the fact is that)
since there is this rule, we can the largest integer representation can not be 255, but rather:
0111 (B) = 7
that the smallest integer it? It is 1111(B) = -7right, wrong! Read on to learn how to represent negative numbers.
You may be more familiar with such a representation, but as long as you remember that there is such a provision on the line.

  • How an integer (including positive and negative numbers) by reverse code
    rules: Decimal> original binary code> binary one
    to binary decimal absolute value conversion original code, if the number is an integer, unchanged (= trans original code symbol) If the number is negative, bitwise inversion, to obtain inverted.
    The following is a list of several anti yard near 0 (if we use four bits, negative numbers must determine how many bits):
Anti binary code Decimal integer
0101 5
0100 4
0011 3
0010 2
0001 1
0000 0
1111 0
1110 -1
1101 -2
1100 -3

From above to below, in fact most of them are well understood, anti-code each time -0001 get the following number (in decimal and this is the same), but we note that there are two zero. We get to discuss why 0000-1111 or 0, in fact, think carefully will find that is indeed the case, as can be seen as 0 and +0 -0, in accordance with the above rules, there are two methods of representation.
That 0000--0001 = 1111 Why is it?
This is because an overflow, you can be understood as the front there are numerous 1 0000, after a sufficient time will forward one by one (but this one is not yet in). Now we discuss the spill still early, this understanding a bit of trouble.
You now know how to counter-decimal numbers into binary code representation, 0 and know that there are two ways, he said on the line.

  • The smallest integer representation of a byte
    observe the anti binary code, you will find that the anti-code representation of negative and positive numbers, not what we want it: the first represents the absolute value of the original code, and then add a 1 or a 0 in front of him becomes positive or negative. So that's why before you think of "1111 (B) is the smallest integer that can be represented" This sentence is wrong, because it is actually represented by 0.
    How to get the smallest integer that it?
    We still look at the list above it in the law, continue to go down until after all three anti-code 0, namely 1000 (B) (the first we could not move, because if this continues to cut down, it will become a positive number! in practice, the computer is like this), we reverse the rules go again, the 1000 (B) is converted to an absolute value, that is, 1000 (B)> 0111 (B )> 7, because it is negative, it is -7, which is a minimum integer of 4 bits can be expressed.
  • Formula to get inverted
    want to get a number of anti-code with the original code conversion method do? This will make the conversion process more versatile. Look at the following formula:



    Wherein n is the number of bits, N being an absolute value of a decimal number
    if we decimal -6 represented by 4 binary bits, n = 4, N = 6, the formula to give N '= 9, then 9 represents the original code to use get the binary number: 1001, it is the anti--6 yards.


Original Address: https: //www.jianshu.com/p/8314710ba093 from = singlemessage?

Guess you like

Origin www.cnblogs.com/jpfss/p/11512978.html