Decimal and N-base conversion (decimal to 36hexadecimal)

Source: Internet
Author: User

The answer is as follows:

Void convert () {Map <int, string> maps; maps [0] = "0"; maps [1] = "1"; maps [2] = "2 "; maps [3] = "3"; maps [4] = "4"; maps [5] = "5"; maps [6] = "6 "; maps [7] = "7"; maps [8] = "8"; maps [9] = "9"; for (INT I = 10, j = 65; I <36, j <91; I ++, J ++) {maps [I] = (char) J ;}cout <"Enter the number to be converted: "; stack <int> stack1; int num; int Lis; int RS; CIN> num; cout <" Enter the number of destination hexadecimal values to be converted :"; cin> Lis; while (num! = 0) {rs = num % Lis; num = num/LIS; stack1.push (RS);} string buffer; For (int K = stack1.size (); k> 0; k --) {int M = stack1.top (); buffer + = maps [m]; stack1.pop ();} switch (buffer. size () {Case 3: Buffer = "0" + buffer; break; Case 2: Buffer = "00" + buffer; break; Case 1: buffer = "000" + buffer; break; Case 0: Buffer = "0000"; break; default: break;} cout <buffer <Endl ;}

Please point out any errors or good suggestions!

Decimal and N-base conversion (decimal to 36hexadecimal)

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.