Reputation: 249
I have a binary file which contains about 2 bytes of data. I am trying to read this data and convert it into hexadecimal and then store it into an unsigned character array. I am currently able to read the binary data, but I am not sure how to convert it into hex and store it into an unsigned char array(All the data read from binary will correspond from 1-9 in Hex). So if the binary data was 00011000 00011000
I would want the unsigned char to be {18,18}. How do I go about converting to hex and then storing it into an unsigned char? This is what I have as of now:
FILE *binaryFile = fopen("securityFile","rb");//type binary file
char hexData[2];
fread(hexData,1,2,binaryFile);
Upvotes: 0
Views: 348
Reputation: 944
use sprintf (or snprintf). see http://libslack.org/manpages/snprintf.3.html
Upvotes: 1