in reply to Re^4: 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, your very question demonstrates that -1 and 0xFFFF_FFFF pack differently.

Replies are listed 'Best First'.
Re^6: Why is pack("N",42949672965) giving me 00 00 00 05
by BrowserUk (Patriarch) on Feb 09, 2015 at 20:05 UTC
    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.

        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