ultoa(), ulltoa()

Updated: October 26, 2022

Convert an unsigned long integer into a string, using a given base


#include <stdlib.h>

char* ultoa( unsigned long int value,
             char* buffer,
             int radix );

char* ulltoa( unsigned long long value
              char* buffer,
              int radix );


The value to convert into a string.
A buffer in which the function stores the string. For 32-bit programs, the size of the buffer must be at least 33 bytes when converting values in base 2 (binary) using the ultoa() function, or at least 65 bytes when using the ulltoa() function. For 64-bit programs, the size of the buffer must be at least 65 bytes when converting values in base 2 (binary) using either the ultoa() or the ulltoa() function.
The base to use when converting the number. This value must be in the range:
2 <= radix <= 36



Use the -l c option to qcc to link against this library. This library is usually included automatically.


The ultoa() and ulltoa() functions convert 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 NUL character is appended to the result.


A pointer to the result, or NULL if an error occurs (errno is set).


The value of the radix argument is not in the valid range.


#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


ultoa() is QNX Neutrino; ulltoa() is Unix

Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes