C language hexadecimal conversion (stack implementation)

Source: Internet
Author: User

C language hexadecimal conversion (stack implementation)
From the last two blogs, we can know that the stack has the characteristics of backward first-in-first-out, while the printing and output of the hexadecimal conversion are just the opposite of the computing process, meeting the requirements of the stack, so we can use the stack to quickly implement the hexadecimal conversion. below is the c function that implements the hexadecimal conversion using the stack.

Void conversion (SqStack * pstack, unsigned int N, const unsigned int d) {if (pstack = NULL) // when the input parameter is a pointer, exit (-1); int mod; // save mod = N % dwhile (N! = 0) {mod = N % d; stack_push (pstack, & mod); // import mod to stack N = N/d;} int top = 0; // display the top-of-stack element printf (convert % d in decimal order to % d and convert it to:, N, d); while (! Stack_is_empty (pstack) {stack_pop (pstack, & top); printf (% d, top);} return ;}

2. Results and Conclusions

 

Related Article

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.