Recursive and hexadecimal Conversions

Source: Internet
Author: User

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;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.