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

Am I missing something. C (Byte), and n (Short) work as expected, but bigger (Long) integers give me 5 (00 00 00 05 instead of FF FF FF FF?
A reverse unpack("N","\xFFFFFFFF") works as well...
#!perl use Data::HexDump; my $bin = pack("N",42949672965); print HexDump($bin);

Replies are listed 'Best First'.
Re: Why is pack("N",42949672965) giving me 00 00 00 05
by BrowserUk (Patriarch) on Feb 08, 2015 at 22:30 UTC

    Because template 'N' is for a unsigned 32-bit value, but 42949672965 requires 36-bits: 0xA_0000_0005; so the high 4-bits are discarded leaving: 0x0000_0005.

    If your Perl is capable, use 'Q' instead for integers > 32-bit.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
Re: Why is pack("N",42949672965) giving me 00 00 00 05
by Eily (Monsignor) on Feb 08, 2015 at 22:29 UTC

    You wrote 42949672965 instead of 4294967295

Re: Why is pack("N",42949672965) giving me 00 00 00 05
by LanX (Saint) on Feb 08, 2015 at 22:33 UTC
    > Am I missing something.

    typo! :)

    DB<122> pack ('N',2**32-1) => "\xFF\xFF\xFF\xFF" DB<123> 2**32-1 => 4294967295 DB<124> 2**32-1 - 42949672965 => -38654705670

    Cheers Rolf

    PS: Je suis Charlie!

Re: Why is pack("N",42949672965) giving me 00 00 00 05
by isync (Hermit) on Feb 09, 2015 at 00:32 UTC
    Arg! Sure sign of too many hours on the keyboard... Fellow monks, thank you very much everyone!
      You know you can use 0xFFFFFFFF, right?

        ... or even 0xFFFF_FFFF or 4_294_967_295 for that matter.


        Give a man a fish:  <%-(-(-(-<

        @ ikegami: yes, knew that.