Created
April 17, 2011 00:02
-
-
Save TkTech/923628 to your computer and use it in GitHub Desktop.
Decimal to Base36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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