in reply to Re^3: comparison of packed signed integers
in thread comparison of packed signed integers
Yes, but the same holds true using 'l>'.
knoppix@Microknoppix:~$ perl -E ' > $pos = pack q{l>}, 10000; > say unpack q{B*}, $pos; > $neg = pack q{l>}, -10000; > say unpack q{B*}, $neg; > say $pos gt $neg ? q{Good} : q{Bad};' 00000000000000000010011100010000 11111111111111111101100011110000 Bad knoppix@Microknoppix:~$
I think that packing with 'N' or 'l>' will always produce the same results, it is unpacking where it makes a difference.
knoppix@Microknoppix:~$ perl -E ' > for ( -2147483648, -1, 0, 1, 2147483647, 4294967295 ) > { > say qq{$_:}; > say unpack q{B*}, pack q{N}, $_; > say unpack q{B*}, pack q{l>}, $_; > say q{-} x 32; > }; > ' -2147483648: 10000000000000000000000000000000 10000000000000000000000000000000 -------------------------------- -1: 11111111111111111111111111111111 11111111111111111111111111111111 -------------------------------- 0: 00000000000000000000000000000000 00000000000000000000000000000000 -------------------------------- 1: 00000000000000000000000000000001 00000000000000000000000000000001 -------------------------------- 2147483647: 01111111111111111111111111111111 01111111111111111111111111111111 -------------------------------- 4294967295: 11111111111111111111111111111111 11111111111111111111111111111111 -------------------------------- knoppix@Microknoppix:~$
However, I'm happy to be corrected if I'm wrong.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: comparison of packed signed integers
by BrowserUk (Patriarch) on Oct 30, 2011 at 12:33 UTC |