Recursively converts a 10 binary number to 16 binary

Source: Internet
Author: User

Code:

#include <stdio.h>CharHextochar (unsignedintnum) {    Switch(num) { Case 0 :            return '0';  Case 1 :            return '1';  Case 2 :            return '2';  Case 3 :            return '3';  Case 4 :            return '4';  Case 5 :            return '5';  Case 6 :            return '6';  Case 7 :            return '7';  Case 8 :            return '8';  Case 9 :            return '9';  Case Ten :            return 'a';  Case  One :            return 'b';  Case  A :            return 'C';  Case  - :            return 'D';  Case  - :            return 'e';  Case  the :            return 'F'; }    return '0';}voidMyhex (unsignedintnum) {unsignedintTMP = num% -; if(num >  ) myhex (num /   +); printf ("%c", Hextochar (TMP));} intMain () {intA =100111; scanf ("%d",&a);   Myhex (a); printf ("\ n"); return 0;}

The highlight is the key to this code's use of recursion: 1 recursion to have important exit conditions 2 the parameters of the external parameters in the recursion, after a series of operations, the data is set to the internal parameters, is a major feature.

Run:

Recursively converts a 10 binary number to 16 binary

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.