Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Pack function

by vrajan (Novice)
on Aug 02, 2005 at 06:41 UTC ( [id://480096]=perlquestion: print w/replies, xml ) Need Help??

vrajan has asked for the wisdom of the Perl Monks concerning the following question:

I have 2 versions of perl binaries both built around the same version of perl 4.
This piece of code calculates different values for adbin.
If I change the "pack("n", $addec)" in the last but one line to "pack("N", $addec)" both return the same value.
I would really appreciate it if I get to know the cause for this deviation.
$addr = "A400"; $addec = unpack("N", pack("H8", substr("0" x 8 . $addr, -8))); $adbin = unpack("B*", pack("n", $addec)); print "ADD_bin: $adbin \n";

Replies are listed 'Best First'.
Re: Pack function
by esskar (Deacon) on Aug 02, 2005 at 06:56 UTC
    Which one do you get? 1010010000000000 or 00000000000000001010010000000000? If you get the big one, the one perl probably is build using 64bit or something similar!
      With "n" i get 1000000000000000 in one binary and 1010010000000000 in the other.
      With "N" i get 00000000000000001010010000000000 with both binaries.
        perldoc -f pack says:
        n An unsigned short in "network" (big-endian) order.
        N An unsigned long in "network" (big-endian) order.

        IMHO it can't be endian problem!?!

        One is running on a little-endian machine and the other on a big-endian?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re: Pack function
by davorg (Chancellor) on Aug 02, 2005 at 11:45 UTC
    both built around the same version of perl 4

    Why? Go on, treat yourself. Install a version of Perl that was released this century :)

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://480096]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-19 03:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found