Hi: Let's say I read 512 bytes from a sector into variable sector.
Code:
unsigned char sector[512];
FILE * infile;
int main(){
.................
infile= fopen("/dev/sda", "r");
fread(sector, sizeof(sector), 1, infile);
.................
What I read into sector could be something like
Code:
00000000 fa eb 21 01 b4 01 4c 49 4c 4f 17 02 76 1e c4 53 |úë!.´.LILO..v.ÄS|
00000010 00 00 00 00 57 b9 e5 01 42 07 f3 4c 81 00 80 60 |....W¹å.B.óL...`|
Now, how could I print the contents of sector? The first byte is 0xfa. So, I should print "f" and "a" to see the first byte. How do I translate 0xfa to the string "fa"?
|Assuming the byte is in c, of type char, I could do
Code:
char car;
car = c >> 4;
if(car > 9) car = car + 7;
car = car + 0x30 // "0" is ASCII char 0x30
printf("%s", car);
And I can print the low nibble in an analogous way. And repeat this operation for each of the 512 bytes in sector. But is there not a more simple way to do this?