lltoa() — Convert long long into a string


Standards / Extensions C or C++ Dependencies
z/OS® UNIX both z/OS V1R5


#include <stdlib.h>

char * lltoa(int64_t ll, char * buffer, int radix);
Compile requirement: Use of this function requires the long long data type. See z/OS XL C/C++ Language Reference for information on how to make long long available.

General description

The lltoa() function coverts the int64_t ll into a character string. The string is placed in the buffer passed, which must be large enough to hold the output. The radix values can be OCTAL, DECIMAL, or HEX. When the radix is DECIMAL, lltoa() produces the same result as the following statement:
(void) sprintf(buffer, "%lld", ll);
with buffer the returned character string. When the radix is OCTAL, lltoa() formats int64_t ll into an unsigned octal constant. When the radix is HEX, lltoa() formats int64_t ll into an unsigned hexadecimal constant. The hexadecimal value will include lower case abcdef, as necessary.

Returned value

String pointer (same as buffer) will be returned. When passed an invalid radix argument, function will return NULL and set errno to EINVAL.

Usage notes

  1. This is a non-standard function. Even though the prototype given is commonly used by compilers on other platforms, there is no guarantee that this function will behave the same on all platforms, in all cases. You can use this function to help port applications from other platforms, but you should avoid using it when writing new applications, in order to ensure maximum portability.



   This example reads an int64_t and formats it to decimal, unsigned
   octal, unsigned hexadecimal constants converted to a character


#include <stdio.h>
#include <stdlib.h>

int main ()
   int64_t i;
   char buffer [sizeof(int64_t)*8+1];
   printf ("Enter a number: ");
   if (scanf ("%lld",&i) == 1) {
      lltoa (i,buffer,DECIMAL);
      printf ("decimal: %s\n",buffer);
      lltoa (i,buffer,HEX);
      printf ("hexadecimal: %s\n",buffer);
      lltoa (i,buffer,OCTAL);
      printf ("octal: %s\n",buffer);
   return 0;


If the input is 1234, then the output should be:
decimal: 1234
hexadecimal: 4d2
octal: 2322

Related information