PDA

Click to See Complete Forum and Search --> : read binary file


lek_70
Feb 3rd, 2002, 02:34 AM
I read the binary code of an file with _open(). The data read to the buffer with _read(). I need to translate this constant char[] to hex value, what function can I use??
eg: data in buffer buff[0]= ef, buff[1]=01

what I need is at the end I can get a long value 0xef01, how to make it??

Or there is other function to read binary file where the output is store in integer value? I am using visual studio C++ 6.0. Thanks.

jim mcnamara
Feb 5th, 2002, 09:21 PM
You've already got binary information, just not in hex format.

Let's say you read in a buffer (buf) of 512 bytes, using a pretend function called readmyfile(I'm not writing a binary read function here, merely showing hex conversion):

Use the HexFromBin function

// prototype so you know what the call looks like
void HexFromBin(
LPBYTE pb,
int cb,
LPTSTR sz
);
main(){
char buf[513];
readmyfile(buf);
LPSTR myHexString;

HexFromBin((LPBYTE) buf, 512, myHexString);
printf("%s\n",myHexString);
}