ultoa
char * ultoa ( unsigned long value, char * buffer, int radix ); | stdlib.h |
cplusplus.com |
Convert unsigned long integer to string.
Converts an unsigned long value to a null-terminated string using the
specified radix and stores the result in the given buffer.
buffer should be large enough to contain any possible value:
(sizeof(unsigned long)*8+1) for radix=2.
Parameters.
Return Value.
A pointer to the string.
Portability.
Not defined in ANSI-C. Supported by some compilers.
Example.
/* ultoa example */
#include <stdio.h>
#include <stdlib.h>
main ()
{
unsigned long ul;
char buffer [sizeof(unsigned long)*8+1];
printf ("Enter a number: ");
scanf ("%lu",&ul);
ultoa (ul,buffer,10);
printf ("decimal: %s\n",buffer);
ultoa (ul,buffer,16);
printf ("hexadecimal: %s\n",buffer);
ultoa (ul,buffer,2);
printf ("binary: %s\n",buffer);
return 0;
}
Output:
Enter a number: 120000
decimal: 120000
hexadecimal: 1d4c0
binary: 11101010011000000