Base isCarry counting system, is a manually defined counting method with carry (there are counting methods without carry, such as the original knotCounting method, the "positive" character counting method commonly used in ticket singing, and the similar tally mark counting).For any kind of base -- X base, it means that the number operation on each bit is carried forward one bit every X.decimal systemEvery ten years,hexadecimalEvery 16 years,BinaryIt means every two to one, and so on. X base is every x carry.
Carry system/positionCounting methodIt is a way of counting, so it is also calledCarry notation, all numerical values can be represented by a limited number of symbols.AvailableNumeric symbolThe number of is called cardinality (en: radius) orbase numberThe radix is n, which is called n-carry system, or n-base for short.Now the most commonly used isdecimal system, usually 10Arabic numeralsCount from 0 to 9.
For any number, we can use different carry systems to express it.For example, the decimal number 57 (10) can be usedBinaryIt can also be expressed as 111001 (2)PentadecimalIt is expressed as 212 (5), and can also be usedoctal number systemExpressed as 71 (8)hexadecimalIt is expressed as 39 (16), and the values they represent are the same.
Because of humananatomyThere are ten fingers in both hands, so the decimal system is the most common one among the carry systems spontaneously adopted by human beings.The idiom "a handful" in a sense describes aSimple countingAndPrimitive humanWhen it comes to counting, the first thought is to use naturalCalculation——Fingers to count.
The value itself is a mathematicalabstract conception。After long-term evolution, integration, selection and elimination, the system is simple and fully functionaldecimal systemThe counting method has become the mainstream counting method in human cultureelementary educationMost people have mastered the decimal counting method since childhood.There are ten in the trayAppleBy counting apples, we abstract out the value of "ten", which is stored and displayed in our mind in the form of "10", a decimal code, rather than other forms.From this point of view, decimal coding is almost the value itself.
The base number of decimal system is 10, and the number is composed of 0-9. The counting ruleEvery decadeI.
Binary
BinaryIt has two characteristics: it consists of two digits 0 and 1,Binary numberThe operation rule is every two into one.
To distinguish from other bases,BinaryIn the writing of numbers, the radix 2 is usually marked at the bottom right of the number, or B is added after the number, where B is the first letter of the English binary binary.
For example, binary number 10110011 can be written as (10110011)two, or written as 10110011B.aboutDecimal numberIt can be left blank or suffixed with D, where D is English decimalDecimalThe initial D of.In the computer field, we use binary for counting because binary has the following advantages:
1. There are only two digits 0 and 1 in the binary number, which can be differentstable stateTo represent a digit.For example, whether the current of a certain path in the circuit is present, the voltage of a certain node is high or low,transistorOn and off, etc.
2. The binary number operation is simple, greatly simplifying the structure of the calculation unit in the calculation.
Basic addition and multiplication of binary numbersAlgorithmThere are four for each, as follows:
However, there is an inconvenience in the daily use of binary counting, that is, the number of digits is often very long, and it is difficult to read and write. For example, writing the decimal 100000D into binary is 11000011010100000B, so what we actually use in the computer field ishexadecimal。When a binary number is converted to a hexadecimal number, the length is reduced to about a quarter of the original length, and the decimal 100000 is written asoctal number systemIt is 303240.One digit in hexadecimal system can represent four digits in binary system.Thus, the decimal 100000 written in hexadecimal is 186A0.
octal number system
becausebinary dataR is small, so it is inconvenient to write and read binary dataMinicomputerIntroduced inoctal number system。The base number of octal is R=8=2 ^ 3. There are digits 0, 1, 2, 3, 4, 5, 6, and 7, and each digit exactly corresponds to three binary digits. Therefore, octal can reflect binary very well.Octalsubscript8 or data followed by O, for example: binary data (11 101 010.010 110 100)twoCorresponding octal data (352.264)eightOr 352.264O.
hexadecimal
Because binary numbers are in usemedianIt is too long to remember, so it proposes a hexadecimal number.
Hexadecimal numbers have two basic characteristics: they are composed of hexadecimal numbers: numbers 0 to 9 plus letters A-F (they representDecimal number10~15), the operation rule of hexadecimal number is every hexadecimal number, that is, the cardinal number R=16=2 ^ 4. Usually, the tail mark H or subscript 16 is used to distinguish between themC languageAdd the prefix 0x to represent hexadecimal numbers.
For example, the hexadecimal number 4AC8 can be written as (4AC8)sixteen, or written as 4AC8H.
For the formal decimal representation, we can start from 0 and number each digit of the number, that isOnesFrom left to left, they are numbered 0, 1, 2;Symmetrical, fromdecimal pointThe next digit is - 1, - 2
conductDecimal conversionWe may as well set the base of the source base (the base used before conversion) as R1, the base of the target base (the base used after conversion) as R2, and the original value is expressed in digits asAnA(n-1)……AtwoAoneAzero.A-1A-2……,RonestayRtwoIn is represented byR, there is (AnA (n-1)...... A2A1A0.A-1A-2……)R1=(An*R^n+A(n-1)*R^(n-1)+……+A2*R^2+A1*R^1+A0*R^0+A-1*R^(-1)+A-2*R^(-2))R2
(Since font cannot be selected here, the description is as follows: An, A2,A-1In the equal sign, n, 2, - 1, etcShould beChange to subscript, and the power of superscript is prefixed with ^)
give an example:
OneDecimal number110, where 1 in the hundreds represents 1 10 ^ 2, i.e. 100, 1 in the tens represents 1 10 ^ 1, i.e. 10, and 0 in the tens represents 0 10 ^ 0, i.e. 0.
A binary number 110, where the high order 1 represents 1 2 ^ 2, that is, 4, the low order 1 represents 1 2 ^ 1, that is, 2, and the lowest order 0 represents 0 2 ^ 0, that is, 0.
A hexadecimal number 110, where the high order 1 represents 1 16 ^ 2, that is, 256, the low order 1 represents 1 16 ^ 1, that is, 16, and the lowest order 0 represents 0 16 ^ 0, that is, 0.
Visible, inNumber systemIn, the size of the value represented by each number is not only related to the size of the number itself, but also related to the location of the number. We call this relationship the number'sPosition power。
Decimal numberThe bit weight of a binary number is a power based on 10, the bit weight of a binary number is a power based on 2, and the bit weight of a hexadecimal number is a power based on 16.Digits are arranged from high to low in the way of power reduction.
The rules for converting binary numbers and hexadecimal numbers to decimal numbers are the same.Press the binary number (or hexadecimal number)Position powerForm expands the form of polynomial sum, and the final sum is its corresponding decimal number, which is called "sum by weight" for short
For example: (1001.01) 2 binary calculation.
Solution: (1001.01) 2
=8*1+4*0+2*0+1*1+0*(1/2)+1*(1/4)
=8+0+0+1+0+0.25
=9.25
Convert (38A. 11) 16 to decimal number
Solution: (38A. 11) 16
=3 × 16 to the power of 2+8 × 16 to the power of 1+10 × 16 to the power of 0+1 × 16 to the power of - 1+1 × 16 to the power of - 2
=768+128+10+0.0625+0.0039
=906.0664
twoDecimal numberConvert to binary number, hexadecimal number (except 2/16 remainder method)
Integer conversion. onedecimal systemInteger conversion to binary integer usually adopts the division and remainder method, that is, use 2 to divide decimal numbers continuously until the quotient is 0,Reverse orderarrayremainderIt is called the division and remainder method for short
Similarly, putDecimal numberWhen converting to hexadecimal number, convert radix 2 to 16
Example: Convert 25 to hexadecimal number
Solution: 25 ÷ 16=1 remainder 9
1 ÷ 16=0 Remainder 1
So 25=(19) 16
3. Conversion between binary number and hexadecimal number
Since there are exactly 16 4-bit binary numbersCombination status, that is, 1-bit hexadecimal number and 4-bit binary number areOne-to-one correspondenceTherefore, the conversion between hexadecimal numbers and binary numbers is very simple
(1) Hexadecimal numbers can be converted into binary numbers as long as each hexadecimal number is replaced by the corresponding 4-bit binary number - referred to as four bit division
Example: Convert (4AF8B) 16 to binary number
Solution: 4 A F 8 B
0100 1010 1111 1000 1011
So (4AF8B) 16=(1001010111110001011) 2
(2) Binary numbers are converted into hexadecimal numbers. From left to right, every four bits are grouped, and the hexadecimal numbers corresponding to each group of four bits of binary numbers are written in turn - four bits in one for short
Example: Convert binary number (000111010110) 2 to hexadecimal number
Solution: 0001 1101 0110
1 D 6
So (111010110) 2=(1D6) 16
During conversion, 0 must be added to complete 4 bits if the last group is less than 4 bits
Any R-ary data can be expanded and added according to weightDecimal numberAccording to.For example: N=1101.0101B=1 * 2^3+1*2^2+0*2^1+1*2^0+0*2^-1+1*2^-2+0*2^-3+1*2^-4 = 8+4+0+1+0+0.25+0+0.0625 = 13.3125
N = 5A.8H = 5*16^1+A*16^0+8*16^-1 = 80+10+0.5 = 90.5
(2) Decimal to R-base
To convert decimal number to R decimal numberInteger partAnd decimal parts are converted respectively
1. Integer conversion --- rules of division R remainder method: (1) use R to remove the decimal numberInteger part, the remainder is taken as the lowest digit of the integer part of the converted R-ary data;(2) Then remove the quotient obtained by R, and take its remainder as the higher digit of the converted R base data;(3) Repeat (2) until the quotient is 0.For example: 115 is converted toBinaryData and Hexadecimal data (Figure 2-4), so 115=1110011 B=73 H
2. Decimal conversion --- Rules for rounding by multiplying R: (1) Multiply by RDecimal numberFractional part ofInteger partAs R base after conversiondecimal pointThe last first digit;(2) Then multiply the decimal part of the previous product by R, and take the integer part of the new product as the lower digit of the converted R decimal;(3) Repeat operation (2) until the product is 0 or the required precision digits have been obtained.
3. Decimal Conversion - Integer Decimal Method: For example: 0.321d is converted to binary. Since 321 is not a multiple of 5, it may take a long time to use the remainder method and the rounding method. At this time, we can use the integer decimal method.The principle is as follows:
N is the number of decimal places of the converted binary number
(x)10=(y)2
(x)10*2^n=(y)2*2^n
D=(x) 10 * 2 ^ n: calculate decimal number and round it
And (and), or (or), xor of all bases(XOR)All operations should be converted to binary for operation, and then the digits should be aligned for operation. The specific operation method is the same as that of ordinary and, or, xor, such as: 1and1=1, 1and0=0, 0and0=0, 1or1=1, 1or0=1, 0or0=0, 1xor1=0, 1xor0=1, 0xor0=0.Just ordinaryBinary operation。
For example: 35 (H) and 5 (O)=110101 (B) and 101 (B)=111101 (B)=75 (O)=3D (H)