in reply to Is the documentation for Perl 5.20 'pack' correct?
But that is a different number :)
https://metacpan.org/pod/perlfunc#pack says
The integer formats s, S, i, I, l, L, j, and J ... For example, a 4-byte integer 0x12345678 (305419896 decimal) would be +ordered natively (arranged in and handled by the CPU registers) into +bytes as 0x12 0x34 0x56 0x78 # big-endian 0x78 0x56 0x34 0x12 # little-endian
So I type
Which seems to agree with above and N An unsigned long (32-bit) in "network" (big-endian) order.$ perl -V:byteorder byteorder='1234'; $ perl -e"print 0x12345678 " 305419896 $ perl -e"print unpack q{H*}, pack q{N*}, 0x12345678 " 12345678 $ perl -e"print unpack q{H*}, pack q{N*}, 305419896 " 12345678 $ perl -e"print sprintf q{%x}, 305419896 " 12345678
N packs 305419896 correctly as big-endian, and my machine is big endian (as sprintf shows)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is the documentation for Perl 5.20 'pack' correct?
by ikegami (Patriarch) on Jul 07, 2015 at 00:34 UTC | |
by Anonymous Monk on Jul 07, 2015 at 00:43 UTC | |
by ikegami (Patriarch) on Jul 07, 2015 at 00:46 UTC |