Skip to content

Instantly share code, notes, and snippets.

@kgabis
Created July 19, 2011 20:15
Show Gist options
  • Save kgabis/1093592 to your computer and use it in GitHub Desktop.
Save kgabis/1093592 to your computer and use it in GitHub Desktop.
n int to b base string in C
void itob(int n, char s[], int b)
{
int i = 0, temp;
n = n > 0 ? n : -n;
do {
temp = n % b;
if(temp < 10)
s[i++] = '0' + temp;
else
s[i++] = 'A' + temp - 10;
} while((n /= b) > 0);
s[i] = '\0';
reverse(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment