Compilation of ITOA Functions

Source: Internet
Author: User

The compilation of ITOA functions mainly involves the following factors:

1) Positive and Negative Numbers of numbers

2) If it is 0, the judgment of value/radix is affected. Therefore, do while loop is used for calculation.

3) how to reverse the converted data and exchange data with the first and last two pointers

4) use Radix for scalability

5) The character array is used for conversion, which is conducive to the expansion to hexadecimal notation.

The Code is as follows:

STD: String ITOA (INT value, int Radix, STD: string * s) {(* S) = ""; static char character [] = "0123456789 abcdef "; if (value <0) {(* S) = "-"; value * =-1 ;}do {(* s) + = character [Value % Radix];} while (value/= Radix)> 0); int start = 0; int end = (* s ). size ()-1; if (* s ). size ()> 0 & (* s) [0] = '-') {start = 1;} Char TMP; while (start <End) {TMP = (* s) [start]; (* s) [start] = (* s) [end]; (* s) [end] = TMP; start ++; end --;} return * s ;}

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.