Take the conversion of decimal numbers into binary numbers as an example to illustrate. Other systems are exactly the same way. (Short division is usually used)
For example, how much is decimal 29 converted into binary?
2 | 29 (1-(29 divided by 2, the remainder is 1).
-
2 | 14 (0-(the quotient of 14 in the previous step is divided by 2, and the rest is 0).
-
2 | 7 (1-(the quotient of the previous step is divided by 2, and the remainder is 1).
-
2 | 3 (1-(the quotient of the previous step is divided by 2, and the remainder is 1).
-
2 | 1 (1-(the quotient of the previous step is 1 divided by 2, and the remainder is 1).
-
0-(Stop counting until the quotient is zero).
Then reverse the remainder obtained each time (bottom-up): that is, binary111is decimal 29.
Namely:1x24+1x23+1x2+0x21x20 =16+8+4+0+1=
What about all kinds of binary conversions?
2, 8, 10, 16 binary conversion computer DIY knowledge 2008-06- 12 17:45 reading 43 12 comments 24 font size: large, medium and small, this is one of "no village before, no shop after"
The conversion between different binary systems is purely mathematical calculation. However, you don't have to worry about any complexity, just multiplication or division.
In fact, counting methods are somewhat different in many parts of life. For example, our most commonly used cardinal number 10 actually comes from the fact that people have 10 fingers.
If our ancestors didn't get rid of the indiscriminate situation, I think we must be using the decimal system now. As for binary ... there is no sock called 0 sock, there is a pair of socks called 1 sock, but if there are two socks, we often say: 1 pair of socks.
Also: hexadecimal, such as week. Hexadecimal, such as hours or "a dozen", sexagesimal, such as minutes or angles ... We find question mark characters (? The ASCII value of) is 63, and we can convert it into octal value: 77, and then use' \77' to represent'?' .
Because it is octal, it should be written as' \077', but because C and c++ stipulate that diagonal lines plus 10 decimal numbers are not allowed to represent characters, the 0 here can be omitted. In fact, we seldom need to use escape characters plus octal numbers to represent a character in actual programming, so we only need to understand the contents of section 6.2.4.
6.2.5 When hexadecimal number is converted into decimal number binary, there are two * * * numbers: 0,1; Octal, with eight * * * numbers: 0, 1, 2, 3, 4, 5, 6, 7; 10 cardinal number, with ten * * * numbers: 0 to 9; 16, sixteen * * * numbers ... Wait, did * * people or Indians only invent the number 10? The cardinal number of 16 is from 16 to 1, but we only have ten numbers from 0 to 9, so we use the five letters A, B, C, D, E and F to represent 10,1and respectively. Letters are case-insensitive.
The weight of the zeroth digit of hexadecimal number is the power of 16, the weight of the zeroth digit is 1 of 16, and the weight of the second digit is the power of 1 6 ... Then, in the nth digit (where n starts from 0), if it is a number, Vertical calculation: 2AF5 is converted into 10 radix: 0: 5 *160 = 5; 1:F * 16 1 = 240; 2: A * 16 2。 163 = 8192+-10997 The direct calculation is: 5. 16 3 = 10997 (remember, in the above calculation, a means 10 and f means 15). Now we can see that the key to converting all bases into 10 bases lies in their different weights.
Suppose someone asks you why the decimal number is 1234 1234? You can give him the following formula:1234 =1*103+2 *102+3 *101+4 *106. Any number: 9876, you can't tell whether it is 16 or 10.
C, C++ stipulates that the hexadecimal number of 16 must start with 0x. For example, 0x 1 stands for hexadecimal number 16.
And 1 stands for decimal. Another example is: 0xFF, 0xff, 0X 102A and so on.
X is also case-insensitive. (Note: 0 in 0x is the number 0, not the letter o) Here are some usage examples: int a = 0x100f; int b = 0x 70+a; So far, we have learned all the expressions of decimal numbers:10,8, 16.
The last point is very important. In C/C++, 10 is divided into positive and negative numbers. For example, 12 means positive 12, and-12 means negative 12. But octal and 16 can only be used as unsigned positive integers. If you are in the code: -078, or write: -0xF2, c, C++, it is not regarded as a negative number. 6.2.7 Use hexadecimal numbers in escape characters. Escape characters can also be followed by a hexadecimal number 16 to represent a character.
As described in section 6.2.4? Characters can be represented in the following ways:'?' Enter the character' \77' directly in octal, and the leading 0 '\0x3F' can be omitted in hexadecimal. Again, this section is just for understanding. We seldom use the latter two methods to represent a character, except that empty characters are represented by octal number' \0'.
6.3 Convert decimal numbers into binary, octal and hexadecimal numbers 6.3. 1 10 Convert decimal numbers into binary numbers to get a decimal number, for example, 6. What if it is converted into a binary number? 10 binary number is converted into binary number, which is a process of continuous division by 2: divide the number to be converted by 2 to get quotient and remainder, and continue to divide the quotient by 2 until the quotient is 0. Finally, all the remainders are arranged in reverse order, and the number obtained is the conversion result.
Sounds a little confused? Let's give an example. For example, convert 6 into a binary number.
Divide the number to be converted by 2 to get the quotient and remainder. So: the number to be converted is 6,6÷ 2, the quotient is 3, and the remainder is 0.
Don't tell me you can't count 6 2473! ) "Divide the quotient by 2 until the quotient is 0 ..." Now the quotient is 3, not 0, so divide by 2. Then: 3 ÷ 2, the quotient is 1, and the remainder is 1.
"Divide the quotient by 2 until the quotient is 0 ..." Now the quotient is 1, not 0. Continue to divide by 2. Then: 1 ÷ 2, the quotient is 0, and the remainder is 1 (calculated by pen and paper, the quotient 0 of 1÷2 is greater than 1! ) "Divide the quotient by 2 until the quotient is 0 ... and finally turn all the remainder upside down" Great! Now the quotient is already 0.
We get the remainder by three operations: 0, 1 and 1, and arrange all the remainder in reverse order, that is, 1 10! Hex, the result is 1 10. Replace the above paragraph with a table, which will be:.
Hexadecimal conversion
1 .10 -> 2 (25.625) (10) Integer part: 25/2= 12.
. 1 12/2=6 。
. 0 6/2=3 。
. 0 3/2= 1 。
. 1 1/2=0 。
. 1 Then we write the remainder from bottom to top: 1 100 1, So this 1 100 1 is the decimal part of the binary form of decimal 25: 0.625 * 2 =1.25 0.25 * 2 = 0.50.5 * 2 =1.0 So this. It is the binary form of decimal 0.625, so: (25.625) (10) = (11kloc-0/.10/) (2) Decimal conversion. (2) 5/2, quotient 2 is1; (3)2/2, the quotient 1 is greater than 0; (4) 1/2, quotient 0+ 1. (5) Find the reciprocal of the remainder. The remainder is 10 10, so decimal 10 is converted into binary10/0 2-. Ten (11001.1kloc-0/) (2) integer part: the following 2(x) means 2+0 * 2 (4)+ 1 * 2 (. =25 Fractional part:1* 2 (-1)+0 * 2 (-2)+1* 2 (-3) = 0.625 So: (1001./kloc. The conversion from binary to decimal is as follows: the method of 84265438 stops at the place where the number is 1, multiplies 1 by the n power of 2, and finally adds this 1 multiplied by the n power of 2, which is the decimal number of this binary number. Let's give an example: find the decimal number of 1 10 1 (2) 1 multiplied by 2 is equal to 4; (3) 1 times 2 to the 4th power equals16; (4) 1 times 2 to the fifth power equals 32; (5) Add these results: 1+4+ 16+32=53 3. Ten -> 8 (25.625) (10) integer part: 25/8=3.
. 1 3/8 =0。
. Then we write the remainder in the bottom-up order: 3 1, so this 3 1 is the decimal part of decimal 25: 0.625*8=5, and then we write the integer part in the top-down order: 5, so this 0.5 is the decimal form of decimal 0.625, so: (25.625) (. Ten (3 1.5) (8) Integer part: 3*8( 1)+ 1*8(0)=25 Decimal part: 5*[8(- 1)]=0.625 So (30)
. 9 1/ 16 =0。
. 1 Then we write the remainder in bottom-up order: 19, so this 19 is the fractional part of decimal 25: 0.625* 16= 10 (that is, hexadecimal A or A) Then we write the integer part in top-down order. Ten (19. A) (16) integer part:1*16 (1)+9 *16 (0) = 25 decimal part:10 *1. =0.625 so (19. A) (16) = (25.625) (10) How to convert binary numbers with decimals into octal numbers and hexadecimal numbers? We take (1100101065438. Eight (11001.1kloc-0/) (2) integer part: every three digits are grouped from the back to the front, the missing places are filled with 0, and then converted by decimal method. Then it is: 001=11= 3, and then we write the result in bottom-up order: 3 1, so this 3 1 is binary1/kloc. Then it is converted by decimal method to get: 10 1=5. Then we write the result in top-down order, which is: 5, so this 5 is the octal form of binary 0. 10 1, so: (1kloc-0/0065438+) 2 (31) 1 1 Then we write the results from bottom to top: 1 100 1, so this11kloc-0/is octal 3/kloc-. Decimal part: from the beginning to the end, each digit is converted into three-digit binary number by decimal, and the missing part is supplemented by 0: 5-> 10 1 and then we write the result from bottom to top as:1kloc-0/,so this10/. So: (31.5) (8) = (654382) (19. a) (16) Integer part: from back to front, each bit is converted into a four-digit binary number, and the missing part is supplemented by 0: 9->/kloc-. 000 1 (equivalent to 1), the result is 000 1 1 or1001decimal part: after removing it, everyone will convert it into a four-digit binary number according to decimal. 10 10 so: (19. a)(XVI)=( 1 100 1. 1065438)(II)=( 168)。 Sixteen (11001.1) (2) integer part: every four digits are converted from decimal to one digit, and the deficiency is supplemented by 0:100/kloc-0. 9 000 1->; 1, and the result is 19 decimal part: every four digits are converted into one digit by decimal conversion, and the absence is 0:1010->10-> The result of A is A, so: (11.101) (2) = (19. A) (16) [Edit this paragraph] Second, the decimal conversion of negative numbers is slightly different.
Write a negative number in its complement form first (not discussed here), and then do it according to the method of converting binary into other binary. Example: -9 needs to be converted to octal form.
Then: the complement of -9 is1111kloc-0/1. Then one stroke with three digits111-> 71/kloc-0->; 6 0 1 1->; Then we write the result in bottom-up order: 367, so 367 is the octal form of decimal number -9.
How to convert between binary systems
There are binary, octal, decimal (commonly used) and hexadecimal.
The fastest direct conversion of computer: Start menu → Program → Accessories → Computer: First set the software to scientific mode: select scientific mode in "View". The default value is decimal. You can convert a number to a decimal number by setting a decimal number first and then clicking Convert to Decimal Number.
Of course, there is a way to convert to binary without a computer! Binary to Decimal: For example: (11.101) (2) integer part: the following 2(x) represents the meaning of 2 to the power of x:1* 2. =25 Fractional part:1* 2 (-1) 0 * 2 (-2)1* 2 (-3) = 0.625 So: (1001./kloc-0. The conversion from binary to decimal is as follows: the method of 842 1 stops at the place where the number is 1, multiplies 1 by the n power of 2, and finally adds this 1 by the n power of 2, which is the decimal number of this binary number. Let's give an example: find the decimal number of 1 10 1 (2) 1 multiplied by 2 is equal to 4; (3) 1 times 2 to the 4th power equals16; (4) 1 times 2 to the fifth power equals 32; (5) Add these results:1+4+16+32 = 5310 → 2: (25.625) (10) Integer part: 25/2 =10.
1 12/2=6 。
0 6/2=3 。
0 3/2= 1 。
1 1/2=0 。
1 Then we write the remainder from bottom to top: 1 100 1, So this 1 100 1 is the decimal part of the binary form of decimal 25: 0.625 * 2 =1.25 0.25 * 2 = 0.50.5 * 2 =1.0 So this. It is the binary form of decimal 0.625, so: (25.625) (10) = (11kloc-0/.10/) (2) Decimal conversion. (2) 5/2, quotient 2 is1; (3)2/2, the quotient 1 is greater than 0; (4) 1/2, quotient 0+ 1. (5) Find the reciprocal of the remainder, which is 10 10, so decimal 10 is converted into binary10/0.
1 3/8 =0。
3 Then we write the remainder in bottom-up order: 3 1, so this 3 1 is the decimal part of decimal 25: 0.625*8=5, and then we write the integer part in top-down order: 5, so this 0.5 is the octal form of decimal 0.625, so: (25.625
9 1/ 16 =0。
1 Then we write the remainder in bottom-up order: 19, so this 19 is the fractional part of decimal 25: 0.625* 16= 10 (that is, hexadecimal A or A) Then we write the integer part in top-down order. Then this A is the hexadecimal form of decimal 0.625, so: (25.625) (10) =( 19. a)( 16) 16→ 10:( 19。 A) (16) Integer part: 65438. =25 Decimal part:10 *16 (-1) = 0.625, so (19. A) (16) = (25.625) (10) How to convert binary numbers with decimals into octal numbers and hexadecimal numbers?
How to convert decimal system?
123456789 This is a nine-digit number; 9= 123456789% 10; Divided by 10, the remainder is12345678 =123456789/10; Divide by the remainder, throw away the remainder and you will find123456789 =1*108+2 *107+.
. +8* 10^ 1+9* 10^0; You can take out the number of each bit one by one by division with remainder:13 =1* 23+1* 22+0+1* 20 =1* 65438+divide two sides to get the remainder; Cycle.
. What did you find? To101113 =1* 23+1* 22+0+1* 20 = 65438. The binary form of 13 is 1 10 1, just the opposite; You will also find that the result of addition, subtraction, multiplication and division of numbers has nothing to do with decimal system, but is just a form.
13 divided by 5=2 and the remainder is 3; 1 10 1 divided by 10 1= 10 remainder 1 1, that is to say, decimal is just a form of numbers. No matter what the decimal system is, as long as it is equal, (1 1)2 means binary number (125)8 means octal number (1 * 8 2+2 * 8 1+5 * 8 0) so (65438+5 * 80). kloc-0/+ 1*2^0= 1* 10^ 1+3* 10^0; Therefore, if the period of 13 is divided by 2, the order of taking the remainder is reversed.
Is binary13 =1* 7+6 * 70; 13 cycles divided by 7, and the reverse order of the remainder is 7; So no matter how many binary conversions; Everyone can do this, because the result of addition, subtraction, multiplication and division of numbers has nothing to do with decimal system, but a form; Decimal number is converted into binary number, octal number and hexadecimal number: the method of converting binary number, octal number and hexadecimal number into decimal number: weighted expansion summation method 1. Conversion between binary and decimal numbers: (1) Binary to decimal method: "Weighted expansion summation" Example: (101.01. 2 1+ 1 * 2 0+0 * 2 (- 1)+ 1 * 2 (-2)) 10 = (8+0+2+ 1+.
, increasing in turn, with decimals of-1 and decimals of -2.
, decreasing in turn. Note: Not any decimal fraction can be converted into a binary number with a limited number of digits.
(2) Decimal to Binary Decimal Integer to Binary Number: "Divide by 2 to take the remainder, Reverse arrangement "(divide by 2 to get the remainder) Example: (89)10 = (10/001) 289 ÷ 2 ...144 ÷ 2 ... 5 ÷ 2 ... 1 2 ÷ "(rounded by 2) Example: (0.625)10 = (0.1) 20.625x2 =/kloc-0. Convert octal number into binary number: convert each octal number into a 3-bit binary number to get a binary number.
The corresponding relationship between octal number and binary number is as follows: 000->; 0 100->; 4 00 1->; 1 10 1->; 5 0 10->; 2 1 10->; 6 0 1 1->; 3 1 1 1->; 7 cases: converting octal 37.4 16 into binary number: 37.4160111.100001. 111.1000011) two cases: binary101/kloc. Kloc-0/38+00.011) 2 = (26.14) 8 3. Conversion from hexadecimal to binary: from decimal point, the integer part is left, the decimal part is right, and a hexadecimal number is used for every four digits. Convert Hexadecimal Numbers into Binary Numbers: Convert each hexadecimal number into a 4-bit binary number and you get a binary number.
The corresponding relationship between hexadecimal numbers and binary numbers is as follows: 0000->; 0 0 100->; 4 1000->; 8 1 100->; c 000 1->; 1 0 10 1->; 5 100 1->; 9 1 10 1->; D 00 10 ->2 0 1 10->; 6 10 10->; a 1 1 10->; e 00 1 1->; 3 0 1 1 1->; 7 10 1 1->; b 1 1 1 1->; Example f: convert the hexadecimal number 5DF.9 into binary: 5df.9010111111. 5438+0110111.1001) Two examples: put the binary number/kloc-0. kloc-0/. 1 1 1)2 =(6 1.baike.baidu/view/ 18536? WTP = TT .
How to convert decimal system
1, other decimal conversion
The method is: expand other decimals according to the weight, and then add the items to get the corresponding decimal number.
Example1:n = (101/kloc-0.10/) b = (? )D
Expand n =1* 24+0 * 23+1* 22+1* 20+1* 2-1+2+6558 by weight.
= 16+4+2+0.5+0. 125 =(22.625)D
2. Convert decimal to other decimal systems.
The method is: it is divided into two parts, namely the integer part and the decimal part.
Integer part: (radix division)
Divide the number we want to convert by the radix of the new system and take the remainder as the lowest bit of the new system;
Divide the quotient obtained last time by the new radix, and take the remainder as the second lowest order of the new radix;
Continue the previous step until the final quotient is zero, then the remainder is the highest bit of the new system.
Decimal part: (radix multiplication)
Multiply the decimal part of the number to be converted by the radix of the new decimal system, and take the obtained integer part as the highest bit of the decimal part of the new decimal system.
Multiply the decimal part obtained in the previous step by the radix of the new decimal system, and take the integer part as the second high order of the decimal part of the new decimal system;
Continue the previous step until the decimal part becomes zero. Or meet predetermined requirements.
Example 2: N=(68. 125)D= (? )O
Integer part decimal part
(68. 125)D =( 104. 1)O
3. Conversion from binary to octal and hexadecimal.
Binary is converted into octal and hexadecimal: they satisfy the relationship between 23 and 24, so the binary to be converted is grouped into groups of 3 or 4 bits from low to high. When the high bits are insufficient, add "0" before the significant bits, and then convert each group of binary numbers into octal or hexadecimal.
The above process can be reversed when octal and hexadecimal are converted into binary.
Example 3:N=(C 1B)H= (? )B
(c 1B)H = 1 100/000 1/ 10 1 1 =( 1 100000 1 1)B
What is the principle of binary conversion?
Conversion rules between digital systems 1. Conversion between Decimal Numbers and Non-Decimal Numbers (1) Converting Decimal Numbers into Non-Decimal Numbers is divided into two steps (radix r). Integer part conversion adopts "divide by r to get remainder"; The fractional part is converted by "r rounding".
(2) The method of converting non-decimal numbers into decimal numbers (radix R, weight of the j-th bit Rj): expand by weight and sum. 2. Conversion between non-decimal numbers (1) Conversion between binary numbers and octal numbers ① Method of converting binary numbers into octal numbers. Divided by the decimal point, the integer part goes from right to left, and the decimal part goes from left to right, in groups of three digits. If it is less than three digits, the integer part should be filled with 0 to the left of the high position, and the decimal part should be filled with 0 to the right of the low position, and then the corresponding octal number should be written.
② Method of converting octal number into binary number: replace octal number with three-digit binary number corresponding to octal number. (2) Conversion of Binary Numbers to Hexadecimal Numbers ① Method of converting Binary Numbers into Hexadecimal Numbers: Separate them with decimal points, with integer parts from right to left, decimal parts from left to right, and four digits in a group. If it is less than four digits, fill in 0 to the left of the high-order part of the integer and 0 to the right of the low-order part of the decimal, and then write the corresponding hexadecimal number.
② Method of converting hexadecimal number into binary number: replace the hexadecimal number itself with the four-digit binary number corresponding to the hexadecimal number. V. Illustration Example 1 Converts the decimal number 59.625 into binary.
(Question 2000) (1) The correct thinking and answer of this question: When decimal numbers are converted into binary numbers, the integer and decimal parts should be considered separately. In addition, if you can memorize the following table skillfully and use expansion when converting binary to decimal, you can write the corresponding binary numbers directly.
20 1 25 32 2- 1 0.5 2 1 2 26 64 2-2 0.25 22 4 27 128 2-3 0. 125 23 8 28 256 2-4 0.0625 24 16 29 5 / Kloc-0/2 2 2-5 0.036543 8+025(3) Extension and variation of this question: A. Binary number101.10 can be converted into decimal number.
(question 1998). A)11.8b)11.125c)11.625m)1.
(Question1998) a) 511b) 501c) 41/d) 401c. The decimal number is 0.8/. b)0.654380 1 1 100. 1 100 B) 10 1 100.0 1 1 100 C) 10 100
(200 1 year)-Example 2: Assuming that the result value of 7*7 can be expressed as 6 1 in a certain system, the result value of 6*7 can be expressed as. (200 1) (1) The correct thinking and answer of this question: The knowledge point examined in this question is the conversion of the number system, but candidates are required to skillfully use the concept of radix.
Given 7*7=49D, we can set 6 1 as a decimal number. According to the law of converting decimal number into decimal number, we can get the equation: 6*R+ 1=49, that is, R = 8;; Finally, the result 42D of 6*7 is converted into an octal number. Answer: 52 (2) The mistakes that students are prone to make: they can't correctly understand the meaning of the topic, or even understand the topic.
(3) extension and variation of this question: a number is 152, and its corresponding hexadecimal number is equal to 6AH, that is, B. A) binary number b) octal number c) hexadecimal number d) decimal number example 3 If x =101.
(1) The correct thinking and answer of this question: The knowledge point examined in this question is the logical operation of binary numbers. Candidates should master the following two points: first, logical operation is bitwise independent operation, and second, the rules of OR operation. Answer:1111(2) Students' common mistakes: they can't correctly distinguish or distinguish addition operations.
(3) expansion and variation of this topic: binary codes 0 10 1000 and1101000 and the result of AND operation and10/kloc. a) 10 100 10b) 1 1 1 1 1 10c)
A) 0cahb) 310qc) 201DD)11b (1) The correct thinking and answer of this question: the knowledge points examined in this question are decimals. The basic method to solve the problem is to convert each decimal number into the same decimal number (such as decimal number), and then compare the sizes.
A: D (2) Students are prone to make mistakes: lack of problem-solving ideas and inability to correctly complete the conversion between decimal numbers. (3) The expansion and variation of this question: A. Hexadecimal number 327 is equal to A.
A)807 B)897 C) 143Q D)243Q .
Conversion between binary systems
Decimal system:11.11.
Binary:11011.00011/kloc-0. 5438+00 100 10 10 1 1 1 10 1
-
You can refer to the following conversion methods:
The number you gave is too long after conversion. Let's change it to a small demonstration.
For example: decimal 22.8 15 to binary.
-
Integer and decimal are converted separately.
Divide the integer by 2, and continue to divide the quotient by 2 until you get 0, and the remainder is arranged in reverse order.
22/2 1 1 Yu 0
1 1/2 5 Redundancy 1
5 /2 2 Redundancy 1
2 /2 1 residual 0
1 /2 0 redundancy 1
So the binary of 22 is 10 1 10.
Decimal times 2, rounding, decimal part times 2, rounding to decimal part is 0, and integers are arranged in order.
0.8 125x2= 1.625 rounded 1, and the decimal part is 0.625.
0.625x2= 1.25 rounded 1, and the decimal part is 0.25.
0.25x2=0.5 is rounded to the whole number, and the decimal part is 0.5.
0.5x2= 1.0 Round up 1, and the decimal part is 0. End.
So the binary of 0.8 125 is 0. 1 10 1.
Decimal 22.8 125 is equal to binary10/kloc-0.11.
-
If the landlord is not sure whether his answer is correct, you can go to the following website to test (decimal is supported):
coder toolbox/number/