Link to home
Start Free TrialLog in
Avatar of vaks
vaks

asked on

simple: read C(++) int and double from file

A simple question:

Some C(++) program has written a lot of ints an doubles to a file. (I know the order of these.) I have to read them in perl (to integers and float point numbers).
Help me with some code.

Ints are 4 bytes, doubles 8.
File byte order: most significant byte first.

I could find it out my self, but have don't have the time right now.

Regards
/Vaks
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vaks
vaks

ASKER

That was only half the answer, but I have figured the rest out myself.

For those interested, one reads doubles with:

read (FILE, $buffer, 8);
$buffer = reverse($buffer);
$double = unpack('d',$buffer);

/Vaks