writing hexnumbers bytewise to a binary file

Hello again, some threads earlier I posted a different question for the same problem (thanks for the help there) but was confronted with some other issues.

I am writing to a binary file. At the moment I am doing this by using ofstream in binary mode.

What I need to do now is to put bytes of information to that file - and i would like to do that by writing two-digit-hex numbers which then need to get into the file without much programming, preferably.

When I open the file with a hexviewer, 4 bytes (with the last byte a binary "00000010") should look like that for example:

00 00 00 04

any help appreciated
alex
Last edited on
You could just use the hex prefix (0x) to your numbers:

 
unsigned char i = 0x04;


Or are you trying to convert from a string (in hex number format) to a number?

EDIT: altered to use char as per question asking about bytes
Last edited on
Don't you mean 00 00 00 02, or 00000100?
Topic archived. No new replies allowed.