Home » C Programs » Itoa Function in C

Itoa Function in C

In C, the itoa () function is used to convert an int data type to a string data type. The itoa() function converts a character string from an integer n. Acronym. Definition. ITOA (Integer to ASCII) is a program that converts integers to ASCII characters (American Standard Code for Information Interchange; computer programming)

The string is inserted into the buffer, which must be large enough to accommodate the output. The values for the radix can be OCTAL, DECIMAL, or HEX. Itoa() has the following prototype: char* itoa(int value, char* buffer, int base);

Itoa Function

It also has the base parameter, which transforms it to the appropriate base. Base is set at 10 by default (decimal base). If the conversion is successful, it returns a pointer to the first character of buffer after populating it. Otherwise, NULL is returned. In C, the itoa () function is used to convert an int data type to a string data type.

Binary Number in C

A binary number is made up of two digits: 0s and 1s. Binary numbers have a base of 2 and are represented as such. (101)2 ( 101 ) 2 is an example. A bit is the name given to each digit in a binary integer.

Decimal Number in Itoa Function

In algebra, a decimal number is defined as a number with a decimal point separating the entire number and fractional parts. The digits after the decimal point represent a value less than one. In this program we have executed the itoa function in c

Hexadecimal Number in Itoa Function

The Hexadecimal Number System is a sort of numerical representation in which the base number is 16. That means there are only 16 potential digit values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. To represent the value of any digit, only 4 bits are required. 

Itoa Function in C

//itoa function in c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int a=43325;
char loader[20];
itoa(a,loader,2); 
printf("Binary value = %s\n", loader);
itoa(a,loader,10); 
printf("Decimal value = %s\n", loader);
itoa(a,loader,16); 
printf("Hexadecimal value = %s\n", loader);
return 0;
}

Output:

Binary value = 1001010000110101

Decimal value = 43325

Hexadecimal value = C435