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

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

Replies are listed 'Best First'.
Re^7: Why is pack("N",42949672965) giving me 00 00 00 05
by ikegami (Patriarch) on Feb 10, 2015 at 03:14 UTC

    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.

      Still no difference!:

      print pack('N', -1) eq pack('N', 0xffff_ffff) ? 'Same' : 'Different';; Same print pack('N', -1) eq pack('N', 0xFFFF_FFFF) ? '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
      With the rise and rise of

        ikegami most probably wants to point out the fact that, with a 'Q' specifier, 0xFFFF_FFFF will give a different result.

        While you are certainly right that for "all F's" it is easier to write "one short of overflow", hence "-1", he is certainly right in pointing out that simply going from 0xFFFF_FFFF to 0xFFFF_FFFF_FFFF_FFFF may be an incorrect oversimplification.