|
-
Feb 3rd, 2002, 03:34 AM
#1
read binary file
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.
-
Feb 5th, 2002, 10:21 PM
#2
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
Code:
// 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);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|