in reply to Re^3: Why is pack("N",42949672965) giving me 00 00 00 05
in thread Why is pack("N",42949672965) giving me 00 00 00 05

Why not simply use -1?

$ perl -MDP -we'DHexDump pack ("N", -1)' 0000 ff ff ff ff .... $ perl -MDP -we'DHexDump pack ("Q", -1)' 0000 ff ff ff ff ff ff ff ff ........

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^5: Why is pack("N",42949672965) giving me 00 00 00 05
by ikegami (Patriarch) on Feb 09, 2015 at 18:09 UTC
    Aside from the fact that N is suppose to take an unsigned integer, your very question demonstrates that -1 and 0xFFFF_FFFF pack differently.
      Aside from the fact that N is suppose to take an unsigned integer,

      Hm. pack takes a bunch of bits and interprets them in whatever way you tell if to:

      print unpack 'f', pack 'N', unpack 'N', pack 'f', 3.141592653589793238 +4626433832795;; 3.14159274101257
      your very question demonstrates that -1 and 0xFFFF_FFFF pack differently

      Que! Care to explain what you think you mean by that?

      Neither I nor Perl can see any difference:

      print pack('N', -1) eq pack('N', 0xffffffff) ? 'Same' : 'Different';; Same

      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

        pack takes a bunch of bits and interprets them in whatever way you tell if to

        That's what unpack does, as you demonstrated. pack, on the other hand, is very specific about what it takes.

        Passing negative numbers where an unsigned one is expected currently performs a C cast, but it's undocumented behaviour.

        Neither I nor Perl can see any difference

        To see the difference between using 0xFFFF_FFFF and -1, you just had to substitute 0xFFFF_FFFF for -1 instead of writing an entirely new program. Try again.