Skip to content

Instantly share code, notes, and snippets.

@Grumblesaur
Created April 8, 2015 03:43
Show Gist options
  • Save Grumblesaur/cf8e4d82f56f7bfc88f8 to your computer and use it in GitHub Desktop.
Save Grumblesaur/cf8e4d82f56f7bfc88f8 to your computer and use it in GitHub Desktop.
From a bad code discussion on cplusplus.com
char * itoa(int i,unsigned base){
static char s[sizeof(int)*8+2];
char*t=s+sizeof(int)*8;
int sgn=i>=0?1:-1;
i/=sgn;
do*t--="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz+/"[i%base];while(i/=base,i>0);
if(sgn<0)*t='-';
else++t;
return t;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment