convert an unsigned binary integer to a string
#include <stdlib.h> char *ultoa( unsigned long int value, char *buffer, int radix );
The ultoa() function converts the unsigned binary integer value into the equivalent string in base radix notation, storing the result in the character array pointed to by buffer. A null character is appended to the result. The size of buffer must be at least (8 * sizeof(int) + 1) bytes when converting values in base 2. That makes the size 17 bytes on 16-bit machines, and 33 bytes on 32-bit machines. The radix must be in the range:
2 <= radix <= 36
A pointer to the result.
#include <stdio.h> #include <stdlib.h> void print_value( unsigned long int value ) { int base; char buffer[33]; for( base = 2; base <= 16; base = base + 2 ) printf( "%2d %s\n", base, ultoa( value, buffer, base ) ); } int main( void ) { print_value( (unsigned) 12765L ); return( EXIT_SUCCESS ); }
produces the output:
2 11000111011101 4 3013131 6 135033 8 30735 10 12765 12 7479 14 491b 16 31dd
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
atoi(), atol(), itoa(), ltoa(), sscanf(), strtol(), strtoul(), utoa()