Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: converting artibrary binary data to numeric values

by johngg (Abbot)
on Sep 30, 2012 at 21:57 UTC ( #996547=note: print w/ replies, xml ) Need Help??


in reply to converting artibrary binary data to numeric values

This might help you visualise what is happening when packing and unpacking big- and little-endian values, as mentioned in Corion's reply.

$ perl -E ' > say q{Big-endian}; > $BEflag = pack q{N}, 1; > say unpack q{B*}, $BEflag; > say sprintf q{0x%02x}, ord $_ for split m{}, $BEflag; > say unpack q{N}, $BEflag; > say q{Little-endian}; > $LEflag = pack q{V}, 1; > say unpack q{B*}, $LEflag; > say sprintf q{0x%02x}, ord $_ for split m{}, $LEflag; > say unpack q{V}, $LEflag;' Big-endian 00000000000000000000000000000001 0x00 0x00 0x00 0x01 1 Little-endian 00000001000000000000000000000000 0x01 0x00 0x00 0x00 1 $

I hope this is helpful.

Cheers,

JohnGG


Comment on Re: converting artibrary binary data to numeric values
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996547]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-07-04 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls