On Tue, Mar 14, 2006 at 12:21:40AM +0100, fons adriaensen wrote:
OK, but for floats the situation could be more
complex. On
Intel, the exponent/sign byte is the last one. Is it
always the first one on BE platforms ? If it isn't then
using ntohl() or htonl() wich are designed to work on
32-bit ints will not help.
IEEE 754 defines the layout of a single float:
1 | 8 | 23 |
s | e | f |
|msbit lsbit|msbit lsbit|
from which i'd say the byte order can be derived. the
sign/exponent is in the msb, so it's stored first on BE and
last on LE machines.
For doubles, things are even more fuzzy. Can you just
use
ntohl() and htonl() on both halves, or do these two have
to be swapped as well ? Will either rule produce
consistent results on all platforms ?
doubles are defined similarly; to convert between LE and BE
you have to reverse the bytes or equivalently swap the
reversed 32-bit words.
<sk>