There is a function in "stdlib. H": ITOA; its function is to convert the specified integer to any hexadecimal value (in the hexadecimal value range of 2 ~ 36). The prototype of this function is as follows:
Char * ITOA (INT num, char * STR, int Radix)
Where: num is your given integer;
STR is a string array, in which the converted result is stored.
Radix specifies the hexadecimal value of the conversion output. The minimum value is 2 and the maximum value is 32.
Take this question as an example:
# Include "stdlib. H" // note that you must add this sentence!
Int input;
Char output [20];
......
ITOA (input, output, 2); // because it is converted to binary, the third parameter is 2
Printf ("the binary of % d is % s", input, output );
......
In addition: 1. the ITOA () function returns the pointer pointed to by Str. Generally, no error value is returned.
2. When calling ITOA (), you must use a string of sufficient length to save the converted result.
The maximum length is 17 bytes.
3. Similar to ITOA (), there is also a function: ltoa (), which converts long integers into any
Italian notation (in hexadecimal notation 2 ~ Between 36. The usage is almost the same as that of ITOA.
The maximum length required for changing the result is 33 bytes.
Original link http://bbs.pfan.cn/post-114218.html