convert a binary integer value to a string in a given base
#include <stdlib.h>
char *ltoa( long int value,
char *buffer,
int radix );
char *_ltoa( long int value,
char *buffer,
int radix );
The ltoa() function converts the 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 33 bytes when converting values in base 2. The radix must be in the range:
2 <= radix <= 36
If radix is 10, and value is negative, then a minus sign is prepended to the result.
The _ltoa() function is identical to ltoa(). Use _ltoa() for ANSI/ISO naming conventions.
A pointer to the result.
#include <stdio.h>
#include <stdlib.h>
void print_value( long value )
{
int base;
char buffer[33];
for( base = 2; base <= 16; base = base + 2 )
printf( "%2d %s\n", base,
ltoa( value, buffer, base ) );
}
void main()
{
print_value( 12765L );
}
produces the output:
2 11000111011101 4 3013131 6 135033 8 30735 10 12765 12 7479 14 491b 16 31dd
WATCOM
_ltoa() conforms to ANSI/ISO naming conventions
| Safety: | |
|---|---|
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
atoi(), atol(), itoa(), sscanf(), strtol(), strtoul(), ultoa(), utoa()