I am trying to read hex values from a text file. I then need to store their individual 4 bit binary equivalents so that i can access the individual bits for comparison. In the file the hex is in this format:
5104
de61
567f
And I would like to be able to have each line stored one at a time as binary in such a way that I can access a specific bit, maybe in an array? Like: {0,1,1,0,0,0,0,1...}
My vague attempts at understanding C has yielded this:
int main(int argc, char *argv[]){
FILE *file;
char instructions[8];
file = fopen(argv[1], "r");
while(fgets(instructions, sizeof(instructions), file) != NULL){
unsigned char a[8];
int i = 0;
while (instructions[i] != '\n'){
int b;
sscanf(&instructions[i], "%2x", &b);
a[i] = b;
i += 2;
}
}
fclose(file);
return 0;
}