I want to analyze the complexity of my code and when i saw itoa() function call then i thought is it constant time or is it converted to string by doing % and / operators.(i want to convert integer to its binary string).
int i;
char buffer [33];
printf("Enter a number: ");
scanf ("%d",&i);
itoa (i,buffer,10); //1st
printf ("decimal: %s\n",buffer);
itoa (i,buffer,16); //2nd
printf ("hexadecimal: %s\n",buffer);
itoa (i,buffer,2); //3rd
printf ("binary: %s\n",buffer);
The source code can be found here:
https://en.wikibooks.org/wiki/C_Programming/stdlib.h/itoa
It seems like it's doing the standard mod div approach. Also, one of the external links provides some relative performance benchmarks at the bottom of the page:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.