Example (12.9) digital conversion, example 12.9 digital conversion

Source: Internet
Author: User

Example (12.9) digital conversion, example 12.9 digital conversion

Description
Returns the conversion of any two non-negative integers of different hexadecimal notation (decimal order ~ The given integer is within the range that long can express.
Different hexadecimal notation is ,..., 9, a, B ,..., z) or (0, 1 ,..., 9, A, B ,..., Z ).
About Input
The input contains only one row, which contains three integers a, n, and B. A indicates that the n after it is an a-hexadecimal integer, and B indicates that you want to convert a-hexadecimal integer n to a-hexadecimal integer. A and B are decimal integers, 2 ≤ a, B <36.
About output
The output contains a row. This row has an integer that is the converted hexadecimal number. Uppercase letters are all used for output, that is, (0, 1,..., 9, A, B,..., Z ).
Example Input
15 Aab3 7
Example output
210306
Prompt
Strings can be used to represent Integers of different hexadecimal formats.

# Include <stdio. h> char symbol [256];/* symbol corresponding to the number */int value [256];/* symbol representing the number */void setup () {int j; for (j = 0; j <10; ++ j) {symbol [j] = '0' + j; value ['0' + j] = j ;} for (j = 10; j <36; ++ j) {symbol [j] = 'A' + j-10; value ['A' + j-10] = j; value ['A' + j-10] = j;} long from_base (char * n, int) {long x = 0; while (* n) {x = a * x + value [* n]; n ++;} return x;} char * to_base (long x, char * s, int B) {do {* (-- s) = symbol [x % B]; x = x/B;} while (x); return s ;} int main () {int a = 0, B = 0; char n [256] = {0}; long x = 0; char * p = 0; scanf ("% d % s % d", & a, n, & B); setup (); x = from_base (n, a); p = to_base (x, n + 255, B); printf ("% s \ n", p); return 0 ;}

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.