Arbitrary number hexadecimal conversion

Source: Internet
Author: User

CodeThe function is only available in 62 hexadecimal notation.

Summary:

It is mainly used to simulate manual operations. In each round, the operator is moved to the next round of divisor, and the obtained remainder is saved in the output array. The remainder of the Division is the number smaller than the base number to be replaced.

Key part:

1. Convert the indata character array into an INDA integer array and calculate it.

2. If the first n digits of the quotient obtained in each round are 0, filter them.

3. Output hexadecimal number, which should be output from the forward

 

The related code is as follows:

 

# Define Max 500 <br/> char indata [Max], outdata [Max]; // number of input/output conversions <br/> int inbase and outbase; // base number Storage <br/> int INDA [Max]; // number of conversions for the Operation <br/> int mymap [Max]; // convert characters into ASCII codes <br/> char RMAP [Max]; // convert ASCII codes to characters <br/> int MOD; // remainder size <br/> int size_in, lsh = 0, I, T; <br/> int modata [2 * max], SH [Max]; // remainder and operator <br/> void turn () <br/> {<br/> // record conversion value <br/> for (INT I = 'a '; I <= 'Z'; ++ I) <br/>{< br/> mymap [I] = I-'A' + 10; <br/> RMAP [I-'A' + 10] = I; <br/>}< br/> for (INT I = 'a '; I <= 'Z'; ++ I) <br/>{< br/> mymap [I] = I-'A' + 36; <br/> RMAP [I-'A' + 36] = I; <br/>}< br/> for (INT I = '0 '; I <= '9'; ++ I) <br/>{< br/> mymap [I] = I-'0 '; <br/> RMAP [I-'0'] = I; <br/>}< br/> mod = 0; <br/> size_in = strlen (indata ); <br/> // convert the character array to the int type <br/> for (Int J = 0; j <size_in; ++ J) <br/>{< br/> INDA [J] = mymap [indata [J]; <br/>}< br/> // each loop <br/> while (true) <br/> {<br/> // conditions for termination <br/> If (size_in = 1 & INDA [0] <outbase) <br/>{< br/> modata [mod ++] = INDA [0]; <br/> break; <br/>}< br/> // vendors <br/> for (I = 0; I <size_in-1; + I) <br/> {<br/> Sh [lsh ++] = INDA [I]/outbase; <br/> T = INDA [I] % outbase; <br/> INDA [I + 1] + = T * inbase; // multiply each displacement of the Division by the original number into the next digit <br/>}< br/> Sh [lsh ++] = INDA [I]/ outbase; <br/> // remainder <br/> modata [mod ++] = INDA [I] % outbase; <br/> // 0 <br/> for (I = 0; I <lsh; ++ I) <br/>{< br/> If (SH [I]) <br/> break; <br/>}< br/> Int J; <br/> // division for commodity transfer <br/> for (j = 0; I <lsh; ++ I, ++ J) <br/>{< br/> INDA [J] = sh [I]; <br/>}< br/> size_in = J; <br/> lsh = 0; <br/>}< br/> // move the final result to the output array <br/> for (I = 0; I <MOD; ++ I) <br/>{< br/> outdata [I] = RMAP [modata [I]; <br/>}< br/>

 

PS: when reading a book, we found that binary is very similar to binary tree. The binary number is converted to decimal by the following formula.

For example, there are n digits.

Total = A [0] * 2 ^ (n-1) + A [1] * 2 ^ (n-2) + ..... + A [N-2] * 2 ^ (1) + A [n-1] * 1;

The number of nodes in each layer of a full binary tree is similar.

Number of layer-7 nodes: 2 ^ 0

Number of layer-7 nodes: 2 ^ 1

Number of nodes at Layer N: 2 ^ n

Very interesting, but I don't know where to use it.

Waiting for communication.

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.