I'd concur that the docs are misleading, if not outright wrong:
#! perl -slw
use strict;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'END_C', NAME => 'Endian', CLEAN_AFTER_BUILD =>0;
SV *hexDump( UV in ) {
int i;
char *p = (char*)∈
SV *out = newSVpvn( NULL, 0 );
for( i=0; i<8; ++i ) {
sv_catpvf( out, "%02x", p[i] );
}
return out;
}
END_C
print hexDump( 72623859790382856 );
__END__
C:\test>endian
Use of uninitialized value in subroutine entry at C:\test\endian.pl li
+ne 19.
0807060504030201
(Aside: If anyone groks why I get the uninitialized value in subroutine entry warning; please enlighten me?)
But you have to factor in the context and tools you use to display the results.
For example, the first two below clearly demonstrate big and little endian respectively; the rest show how easy it is to get misleading results:
C:\test>p1
[0] Perl> print unpack 'C*', pack 'Q>', 72623859790382856;;
1 2 3 4 5 6 7 8
[0] Perl> print unpack 'C*', pack 'Q<', 72623859790382856;;
8 7 6 5 4 3 2 1
[0] Perl> print unpack 'H*', pack 'Q<', 72623859790382856;;
0807060504030201
[0] Perl> print unpack 'h*', pack 'Q<', 72623859790382856;;
8070605040302010
[0] Perl> print unpack 'H*', pack 'Q>', 72623859790382856;;
0102030405060708
[0] Perl> print unpack 'h*', pack 'Q>', 72623859790382856;;
1020304050607080
[0] Perl> print unpack 'b*', pack 'Q>', 72623859790382856;;
10000000 01000000 11000000 00100000 10100000 01100000 11100000 0001000
+0
[0] Perl> print unpack 'B*', pack 'Q>', 72623859790382856;;
00000001 00000010 00000011 00000100 00000101 00000110 00000111 0000100
+0
[0] Perl> print unpack 'b*', pack 'Q<', 72623859790382856;;
00010000 11100000 01100000 10100000 00100000 11000000 01000000 1000000
+0
[0] Perl> print unpack 'B*', pack 'Q<', 72623859790382856;;
00001000 00000111 00000110 00000101 00000100 00000011 00000010 0000000
+1
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.