Re: [Dev-C++] read binary data from file
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Adam J. <aj...@i-...> - 2007-08-27 02:21:05
|
>> You wrote: >>Hi, >>how can i read binary data from file and transform it into integer? >>I need to read first two bytes from a file encoded in big-endian and >>transform it into an integer. >>I'm running linux on a Intel at the moment but the file is created by a sun. >>I can i do that? >>Thanks, This is tricky. You really need to know what you are doing here. I am assuming that you have a reason or know that the binary in the file represents integers. Converting binary to integers may not be the correct thing, but if you know that the binary represenst integers, you will need to read the file in a byte at a time. Assemble the bytes in the correct order and then do the simple calculation of switching the assembled bytes into an integer assuming the bytes are in big-endian. This is pretty straight forward assuming you know the binary file specification. -Adam Jones i-softwareproducts.com |