What do you mean "getting some hex"?
I would hope it's all hex, since you're using "%x" in your printf format.
I'm not convinced from your other post that you understand exactly what the file format is.
Consider this example for a single int, stored in two different ways.
Code:
#include <stdio.h>
void writeAsText ( int value, const char *filename ) {
FILE *fp = fopen(filename,"w");
fprintf(fp,"%d\n",value);
fclose(fp);
}
void writeAsBinary ( int value, const char *filename ) {
FILE *fp = fopen(filename,"wb");
fwrite(&value,sizeof(value),1,fp);
fclose(fp);
}
void dumpFile ( const char *filename ) {
FILE *fp = fopen(filename,"rb");
int ch;
printf("Dumping %s\n", filename);
while ( (ch=fgetc(fp)) != EOF ) {
printf("%02x\n",ch);
}
fclose(fp);
}
int main ( ) {
int value = 12345678;
writeAsText(value,"intAsText.txt");
writeAsBinary(value,"intAsBinary.bin");
dumpFile("intAsText.txt");
dumpFile("intAsBinary.bin");
return 0;
}
Result:
Code:
$ gcc foo.c
$ ./a.out
Dumping intAsText.txt
31
32
33
34
35
36
37
38
0a
Dumping intAsBinary.bin
4e
61
bc
00
# count the bytes in each file
$ wc -c intAs*
4 intAsBinary.bin
9 intAsText.txt
13 total
# text is printable
$ cat intAsText.txt
12345678
# hexdump of the files (basically the same output as the program)
$ odx intAsText.txt
000000 31 32 33 34 35 36 37 38 0a >12345678.<
000009
$ odx intAsBinary.bin
000000 4e 61 bc 00 >Na..<
000004
The text representation of an int is variable in length (depending on the magnitude of the int). But the result is easily human readable, and can be loaded into any editor
The binary representation on the other hand results in a fixed number of bytes regardless of the value of the integer. You can only "view" these things properly with a hex editor, or a hex dump utility like 'od'. If you try to read them as text, you'll just get garbage and a smattering of random printable characters (like Na) which bear no relationship to the actual integer value.