Recursive and hexadecimal Conversions
Recursion principle such as function and (n) n = 3 Calculate the factorial {int I; if (n> 0) {I = n * and (n-1);} elsei = 1; return I ;} the first call n = 3 then recursion n-1 = 2 enter the second call n = 2 then recursion n-1 = 1 enter the third call n = 1 then recursion n-1 = 0 the fourth call if the judgment is not true, I = 1 is returned, and then the third call is returned. At this time, n = 1 * If the judgment is not true, the returned I is 1, and I = n + and (n-1) is calculated) = 1*1 = 1 and then return the second call. At this time, n = 2 calculates I = n + and (n-1) = 2*1 = 2 and then return the first call. At this time, n = 3 calculates I = n + and (n-1) = 3*2 = 6 recursively divide the number in decimal number by the number in hexadecimal number you want to convert, and keep the remainder of each division next to it. The resulting commodity number is further divided by the number in hexadecimal number, until the remainder is 0. for example, you want to convert 100 to octal: 100/8 = 12... (The remainder is 4); 12/8 = 1 ..... (The remainder is 4); 1/8 = 0 ...... (The remainder is 1). Then, write the remainder from low to high. The above is 144, which is the octal representation of 100. the conversion from decimal to hexadecimal is the same as that from binary to octal. For example, if 100 is converted to hexadecimal: 100/16 = 6 .... (The remainder is 4); 6/16 = 0 ...... (The remainder is 6). Similarly, the 100 format expressed in hexadecimal format is 64. 100 is converted to binary: 100/2 = 50 .... (The remainder is 0); 50/2 = 25 ..... (The remainder is 0); 25/2 = 12 ..... (The remainder is 1); 12/2 = 6 ...... (The remainder is 0); 6/2 = 3 ....... (The remainder is 0); 3/2 = 1 ....... (The remainder is 1); 1/2 = 0 ....... (The remainder is 1), so the binary representation of 100 is 1100100;