The binary system is a rounding method .
Let's think about the decimal in life:
(1) digital : A concept describing the number of elements contained in a set theory
the basic decimal symbols are:0, 1, 2, 3, 4, 5, 6, 7, 8, 9; We call these decimal digits: that is, the basic symbol, all the decimal is composed of these 10 digital. Every person in overtime is "every ten in one."
(2) position right : the unit value corresponding to each fixed position in the numeral number is called the bit right
so everyone consider a question, say a decimal number, known as the fourth digit is 5, the other bits are 0, then this number is a few? Answer: 5000, how to calculate is 5*104-1; then introduced a concept of power.
for the decimal, we can start from 0, the number of the number of digits are numbered, that is, from the right to the left, sequentially numbered 0,1,2, ... Symmetrical, the number after the small decimal place is -1,-2, ... While n-bits represent the size of the right is 10n-1;
in a computer system, data is expressed in the form of binary information Unit 0,1. So what is the binary system in a computer system?
Binary: Same as decimal, is also a method of counting.
(1) The main reasons for using binary in computer :
1) Technology Implementation is simple, the computer is composed of logic circuit, logic circuit usually only two states, switch on and off, these two states can be used in the "1" and "0" .
2) simplified operation rule : two binary number and, product operation combination each has three kinds, the operation rule is simple, facilitates simplifies the internal structure of the computer, improves the computation speed.
3) suitable for logical operation : logical algebra is the theoretical basis of logical operation, the binary system has only two digital, exactly with the logical algebra " true " and " Fake " Match .
4) easy to convert , binary and decimal numbers are easy to convert to each other.
5) using binary system to represent the data has the advantages of strong anti-jamming ability, high reliability and so on. Because each data only two state, when a certain degree of interference, can still reliably tell whether it is high or low
(2) Binary Digital:0 and 1," every two into one ."
(3) representation of the binary number: method One:(100001)2 Method Two:100001B
(4) binary position:the value on n is 2n-1, such as binary number 100001 exactly is the decimal in our life?
(5) binary Conversion Decimal: method is to sum by the throne
Binary number 100001=1*26-1+0*25-1+0*24-1+0*23-1+0*22-1+1*21-1=32+1=33(Note: Intermediate calculation process is decimal)
(6) binary same as decimal can also be subtraction arithmetic arithmetic, can also be logical operation. Let's take a look at the binary operation.
(7) binary arithmetic :
1000011+111001=? (As with the decimal addition is just a two-in-one can)
1000011-111001 =? ( as with the decimal subtraction just not enough minus, forward a loan, 2 per loan )
Binary multiplication and division and decimal are the same, there is no too much to express.
So how do you convert decimal into binary? only the integers that can be converted are discussed here, not the decimals.
we convert 100 to Binary for example: The method is to use the addition of two methods, before speaking this method, we first look at a formula, in the third grade of primary School, 9÷2=4----1,2 We call the quotient (rounding), 1 we call the remainder.
In addition to the second method of redundancy: In order to find the remainder until the last 0, and then from the bottom up to write down each time the residue composition of the new number.
In this way, the decimal number can be converted to any number of n, except the n method.
After learning the decimal, binary, have to say octal and hex, because the binary represents a large number of bits too many, so the concept of octal, hexadecimal.
Octal number
because the base of the binary data R is small, so the writing and reading of binary data is inconvenient, so the octal is introduced into the minicomputer . octal Base r=8=2^3, there are digital 0, 1, 2, 3, 4, 5, 6, 7, and each digital exactly corresponds to three-bit binary number, so octet can well reflect the binary. Octal binary with subscript 8 or after the data plus O for example: binary data (11 101 010.010 110 100) 2 corresponds to octal data (3 5 2.2 6 4) 8 or 352.264O.
Hexadecimal
because the binary number is in use Number of digits too long, not easy to remember, so the hexadecimal number was raised
The hexadecimal number has two basic characteristics: It consists of 16 characters 0~9 and a,b,c,d,e,f (they represent the decimal number 10~15), the hexadecimal number operation law is every 16 in one, that is, the base r=16=2^ 4, usually in the expression with the tail mark H or subscript 16 to show the difference.
For example: hexadecimal number 4ac8 can be written as (4AC8) 16, or written as 4ac8h.
Conversion between binary number and hexadecimal number
since the 4-bit binary number has exactly 16 combined states, the 1-bit hexadecimal number corresponds to the 4-bit binary number one by one. Therefore, the hexadecimal number and the binary number conversion is very simple.
(1) The hexadecimal number is converted to a binary number , as long as each hexadecimal number is replaced by the corresponding 4-bit binary number-short four bits .
Example: Converting (4af8b) 16 to a binary number.
Solution: 4 A F 8 B
0100 1010 1111) 1000 1011
SO (4af8b) 16 = (1001010111110001011) 2
(2) The binary number is converted to hexadecimal number , to the left, to the right each four-bit group, and then write out each set of 4-bit binary number corresponding hexadecimal number-abbreviation four is a bit.
Example: Converting a binary number (000111010110) 2 to a hexadecimal number .
Solution: 0001 1101 0110
1 D 6
SO (111010110) 2= (1D6) 16
Note that the last set of less than 4 bits must be added 0 to 4 bits when converting
(3) binary and octal binary and binary hexadecimal similar to just every three bits of binary into one octal , and one octal number converted to three-bit binary number .
(4) know the conversion between the number of numbers to understand how to calculate the value between, then we in the computer in the end how to input the computer 100+100 to operate it? Then we must understand the original code, anti-code and complement.
machine number and truth value
Before you learn the original code , the inverse code and the complement , you need to understand the concept of machine number and truth value First .
- Number of machines
a binary representation of a number in a computer , called the number of machines . the number of machines is signed, in the computer with a number of the highest bit of the symbol , positive 0, negative number is 1.
For example, in decimal number +3 , the computer word length is 8 bits, converted to binary is 00000011. If it is -3 , it is 10000011 .
So, the 00000011 and 10000011 Here are the number of machines.
- Truth
Because the first bit is the sign bit, the form value of the machine number is not equal to the true value. For example, the signed number above 10000011 1 Span style= "font-family: Arial" > represents negative, and its true value is -3 131 ( 10000011 converted to decimal equals 131 ). So, for the sake of differentiation, The true value of the number of machines with a signed bit is called the truth of the number of machines
Example: The truth value of 0000 0001 = +000 0001 = +1,0001 True Value =–000 0001 =–1
original code, anti-code and complement
First,because the human brain knows the first bit is the sign bit., in the calculation we will be based on the sign bit, Select the add-minus for the truth region. (The concept of truth value at the beginning of this paper). But for computers, The Plus and minus multipliers are already the most basic operations, to design as simple as possible. Computer Identification"sign Bit"obviously makes the basic circuit design of the computer very complicated.! so people came up with a way to take symbolic bits into operation.. We know, subtracting a positive number from the algorithm equals adding a negative number to it., that: 1-1 = 1 + ( -1) = 0,so the machine can only add and not subtract ., This makes the design of computer operations even simpler..
so people to the symbolic bit participates in the Operation , and only the addition is preserved, thus simplifying the computer operation and inventing the original code , the inverse code and the complement .
The original code , anti-code, and complement are signed with the binary representation of the number of methods . Both symbolic and numeric digits First look at the original code :
- Original code
The original code is the absolute value of the symbolic bit plus the truth , that is, the first digit represents the symbol , and the remaining bits represent the values . For example, if it is a 8 -bit binary :
[+1] Original = 0000 0001
[-1] Original = 0001
the first bit is the sign bit . The remaining 7 bits are numeric digits. because the first bit is the sign bit , The range of values for the 8-bit binary number is :
[1111 1111, 0111 1111]
That
[-127, 127]
The original code is the most easily understood and calculated representation of the human brain .
- Anti-code
The inverse code is represented by :
The inverse of a positive number is its own
negative number of the inverse code is on the basis of its original code , the sign bit is unchanged, the remaining bits are reversed.
[+1] = [00000001] original = [00000001] anti-
[-1] = [10000001] original = [11111110] Reverse
It can be seen that if an inverse code represents a negative number, the human brain cannot visually see its value . it is usually converted to the original code and then calculated .
- Complement
the complement is expressed in the following ways :
A positive complement is its own
The complement of a negative number is on the basis of its original code , the sign bit is unchanged, the rest of you take the counter, the last +1. (That is, on the basis of the anti-code +1)
[+1] = [00000001] original = [00000001] anti = [00000001] complement
[-1] = [10000001] original = [11111110] counter = [11111111] complement
for negative numbers , the complement representation is also the human brain can not intuitively see its value . It is also often necessary to convert the original code to calculate its value .
in the Computer in the system, the values are all represented by a complement (storage). The main reason: the use of complement, the symbol and other bits can be processed uniformly, and subtraction can also be processed by addition. In addition , if the top bit (sign bit) has a carry, the carry is discarded when the number of two is summed by the complement, and the complement is almost identical to the original code conversion process.
Binary conversion and original code complement