Skip to content

Instantly share code, notes, and snippets.

@TkTech
Created April 17, 2011 00:02
Show Gist options
  • Save TkTech/923628 to your computer and use it in GitHub Desktop.
Save TkTech/923628 to your computer and use it in GitHub Desktop.
Decimal to Base36
#include <stdio.h>
#include <stdint.h>
#include <string.h>
char *base36 = "0123456789abcdefghijklmnopqrstuvwxyz";
void encode36(char *buffer, uint64_t num) {
for(num=num; num > 0; num /= 36) {
*buffer++ = base36[num % 36];
}
}
void flip(char *buffer) {
size_t x, y;
for(x=0,y=strlen(buffer) - 1; x < y; x++, y--) {
buffer[x] ^= buffer[y];
buffer[y] ^= buffer[x];
buffer[x] ^= buffer[y];
}
}
int main (int argc, const char * argv[])
{
char output[14] = {0};
encode36(output, 1000000000000);
flip(output);
printf("%s\n", output);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment