Hello,
I have below code.
FILE *fp;
int a;
fp=fopen("dump.bin","wb");
a = 0xffafbcdf;
fprintf(fp,"%x",a&0x3ffff);
I am trying to dump only 18 LSBits of variable a. But the value dumped in the file is 3bcdf.
My question - Is it not possible to dump/fwrite/fprintf desired number of bits which is not a multiple of 4(nibble) to a file?
Thank you
EDIT:
1.) When i checked the output of my file dump i realized, since i am opening file in binrary mode, i should not be using fprintf, but i should use fwrite.
2.) What i see in the output is DF BC 03 , it writes in multiples of 8 bits, so it writes 24 bits(3 bytes) but i was interested in only 18 bits. But then i realised thatno file write library will be able to write non-multiple of 8 bits to a file. it will always add leading zero bits to complete the byte and then dump it. "Least count unit" for a file data is a byte.
-AD.