shenme has asked for the wisdom of the Perl Monks concerning the following question:
had occurred to me, the other one$num = unpack "f", reverse $packed_num;
just 'feels' wrong. Before finding that thread I had tried$float = unpack "f", pack "N", unpack "V", $data;
which also works.$float = unpack 'f', pack 'L', unpack 'N', $data;
Now the fact is that on the Intel platforms pack 'N', unpack 'V', $data and pack 'L', unpack 'N', $data both accomplish the transformation from big-endian to little-endian byte order. But it seems to me that I _should_ use 'N' first on the network-order 4-byte value, then force the 4-byte value to a native order 4-byte value, and only then convert to a native float value. In this way the same code would work on non-Intel machines?
I guess I'm asking, which is the more pedant-proof answer?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Network IEEE 754 to Native Floats: which pack/unpack ops better?
by Roger (Parson) on Nov 25, 2003 at 22:55 UTC | |
by shenme (Priest) on Nov 26, 2003 at 00:16 UTC | |
|
Re: Network IEEE 754 to Native Floats: which pack/unpack ops better?
by Stevie-O (Friar) on Nov 25, 2003 at 23:04 UTC |