Skip to content

Instantly share code, notes, and snippets.

@cwage
Created June 22, 2013 20:31
Show Gist options
  • Save cwage/5842473 to your computer and use it in GitHub Desktop.
Save cwage/5842473 to your computer and use it in GitHub Desktop.
mystring base64tobinary(mystring source)
{
int i;
int index;
char base64[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char *tmp;
char *chunk;
for (i = 0; i < source.length; i++)
{
tmp = strchr(base64, source.text[i]);
index = (int) (tmp - base64);
chunk = dectobinary(index);
printf("%s\n", chunk);
}
}
char* dectobinary(int source)
{
char result[7];
result[0] = '\0';
int i, k;
for (i = 5; i >= 0; i--)
{
k = source >> i;
if (k & 1)
strcat(result, "1");
else
strcat(result, "0");
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment