I need to write hex into a binary file, i.e., '00A8' (decimal 168)
output as 2 bytes, 'FE' (decimal 254) output as 1 byte, etc.
Suggestions??
Don't cross-post between groups for unrelated languages unless
you're prepared for a lot of useless information that doesn't
apply to your language of choice. For instance, this is how
you'd do it in C, but the preferred C++ way is subtly different
(e.g., at least using <cstdio>, if not some clever <iostream>
manipulation).
Followups set to comp.lang.c on this subthread.
#include <stdio.h>
int main(void)
{
FILE *myfile = fopen("filename", "wb");
putc(0x00, myfile);
putc(0xA8, myfile);
putc(0xFE, myfile);
fclose(myfile);
return 0;
}
HTH,
-Arthur