Is there any lib witch i can use to convert integers and floats between different architecture representation?
ie. -255 with big-endian 2byte signed integer is: 0xff7f and for 4 byte signed integer is 0xffffff7f and same with other…
I have found Binary tools package in PEAR, but it status is unmaintained and stopped at 0.3.0 version, i’m not sure if it will produce correct results.
[EDIT]
I know about function pack, but it’s results like said in manual are machine dependent, witch is not the result i want to have
The
packfunction has, for integers, several modes that are not machine-dependent:For floats, there’s no such thing:
However, virtually all the systems will use IEEE 754 single precision for “float” and double precision for “d”.
So, the only thing that’s variable is endianness. You could check the endianness of the system where the system is running for instance doing:
And then reversing the endianness of the data with
strrev, if appropriate.