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 ;}