Commit e53583e0 authored by Sam Schmalzried's avatar Sam Schmalzried

made rough versions of hex to binary functions

parent 17e6cadc
......@@ -2,8 +2,28 @@
#include <stdio.h>
#include <string.h>
char* hexToBinary(char*);
char* binaryTo64(char*);
void hexToBinary(char*, char*);
char* hexQuads(char);
void binaryTo64(char*, char*);
char quads[16][4] = {
"0000",
"0001",
"0010",
"0011",
"0100",
"0101",
"0110",
"0111",
"1000",
"1001",
"1010",
"1011",
"1100",
"1101",
"1110",
"1111"
};
int main(int argc, char* argv[]) {
if (argc == 1) {
......@@ -13,19 +33,32 @@ int main(int argc, char* argv[]) {
char* binaryString, base64String;
binaryString = hexToBinary(argv[1]);
hexToBinary(argv[1], binaryString);
return 0;
}
char* hexToBinary(char* hexString) {
char* binaryString = malloc(4 * sizeof(hexString));
return strdup(binaryString);
void hexToBinary(char* hexString, char* binaryString) {
int i, len = strlen(hexString);
char c;
printf("len = %f", len);
for (i = 0; i < len; i++) {
c = *(hexString+i);
strcat(binaryString, hexQuads(c));
}
}
char* hexQuads(char c) {
if (c >= '0' && c <= '9') return quads[c - '0'];
if (c >= 'A' && c <= 'Z') return quads[10 + c - 'A'];
if (c >= 'a' && c <= 'z') return quads[10 + c - 'a'];
return -1;
}
char* binaryTo64(char* binaryString) {
char* base64String = malloc(sizeof(binaryString));
return strdup(base64String);
void binaryTo64(char* binaryString, char* base64String) {
printf("Now in binaryTo64\n");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment