Base

Carry counting system
Collection
zero Useful+1
zero
Base is Carry counting system , is a manually defined counting method with carry (there are counting methods without carry, such as the original knot Counting 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 system Every ten years, hexadecimal Every 16 years, Binary It means every two to one, and so on. X base is every x carry.
Chinese name
Base
Foreign name
system of numeration
Substantive
It is a carry method stipulated by people
Example
Decimal, hexadecimal, binary

Introduction to terms

Announce
edit
Carry system/position counting method
Carry system/position Counting method It is a way of counting, so it is also called Carry notation , all numerical values can be represented by a limited number of symbols. Available Numeric symbol The number of is called cardinality (en: radius) or base number The radix is n, which is called n-carry system, or n-base for short. Now the most commonly used is decimal system , usually 10 Arabic numerals Count 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 used Binary It can also be expressed as 111001 (2) Pentadecimal It is expressed as 212 (5), and can also be used octal number system Expressed as 71 (8) hexadecimal It is expressed as 39 (16), and the values they represent are the same.

Base list

Announce
edit

decimal system

Human beings naturally choose decimal system
Because of human anatomy There 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 a Simple counting And Primitive human When it comes to counting, the first thought is to use natural Calculation ——Fingers to count.
Decimal coding It is almost the value itself.
The value itself is a mathematical abstract conception After long-term evolution, integration, selection and elimination, the system is simple and fully functional decimal system The counting method has become the mainstream counting method in human culture elementary education Most people have mastered the decimal counting method since childhood. There are ten in the tray Apple By 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 rule Every decade I.

Binary

Binary It has two characteristics: it consists of two digits 0 and 1, Binary number The operation rule is every two into one.
To distinguish from other bases, Binary In 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. about Decimal number It can be left blank or suffixed with D, where D is English decimal Decimal The 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 different stable state To 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, transistor On 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 numbers Algorithm There are four for each, as follows:
0+0=0,0+1=1,1+0=1, 1+1 =10
0×0=0,0×1=0,1×0=0,1×1=1
3. Binary natural compatibility Logical operation
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 is hexadecimal 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 as octal number system It 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

because binary data R is small, so it is inconvenient to write and read binary data Minicomputer Introduced in octal 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. Octal subscript 8 or data followed by O, for example: binary data (11 101 010.010 110 100) two Corresponding octal data (352.264) eight Or 352.264O.

hexadecimal

Because binary numbers are in use median It 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 represent Decimal number 10~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 them C language Add 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 is Ones From left to left, they are numbered 0, 1, 2; Symmetrical, from decimal point The next digit is - 1, - 2
conduct Decimal conversion We 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 as A n A n -1) …… A two A one A zero . A -1 A -2 ……, R one stay R two In is represented by R , there is (AnA (n-1)...... A2A1A0.A-1 A-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-1 In the equal sign, n, 2, - 1, etc Should be Change to subscript, and the power of superscript is prefixed with ^)
give an example:
One Decimal number 110, 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, in Number system In, 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's Position power
Decimal number The 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.

Forward conversion

Announce
edit
one Binary number hexadecimal Number converted to Decimal number (sum by weight)
The rules for converting binary numbers and hexadecimal numbers to decimal numbers are the same. Press the binary number (or hexadecimal number) Position power Form 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
two Decimal number Convert to binary number, hexadecimal number (except 2/16 remainder method)
Integer conversion. one decimal system Integer 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 order array remainder It is called the division and remainder method for short
Example: Convert 25 to binary number
Solution: 25 ÷ 2=12 Remainder 1
12 ÷ 2=6 Remainder 0
6 ÷ 2=3 Remainder 0
3÷2=1 remainder one
1 ÷ 2=0 Remainder 1
So 25=(11001) 2
Similarly, put Decimal number When 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 numbers Combination status , that is, 1-bit hexadecimal number and 4-bit binary number are One-to-one correspondence Therefore, 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
Number system conversion Generalization of
(1) R base Convert to decimal
Any R-ary data can be expanded and added according to weight Decimal number According 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 number Integer part And decimal parts are converted respectively
1. Integer conversion --- rules of division R remainder method: (1) use R to remove the decimal number Integer 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 to Binary Data and Hexadecimal data (Figure 2-4), so 115=1110011 B=73 H
2. Decimal conversion --- Rules for rounding by multiplying R: (1) Multiply by R Decimal number Fractional part of Integer part As R base after conversion decimal point The 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
D → T conversion Binary number
(y) 2=T/2 ^ n=T * 2 ^ (- n
give an example:
0.321 converted to binary number, 7 bits reserved
0.321 * 2 ^ 7=41.088, integer 41
41=32+ 8+1 That is 100000+1000+1=101001
Withdrawal, 7 digits are required to be reserved because there are only 6 digits, so it is 0.0101001
Check with online conversion tool, correct
and、or、 xor operation
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 ordinary Binary operation
For example: 35 (H) and 5 (O)=110101 (B) and 101 (B)=111101 (B)=75 (O)=3D (H)