++sn1987a (when the Vote Fairy next visits) for an ingenious observation! Unfortunately, I don’t think it answers the OP’s question, as masking with bitwise-AND does remove the sign bit, even with use integer in effect:
#! perl
use strict;
use warnings;
print "\nno integer\n";
my $bit = -1 >> 31;
printf "unmasked: 0x%x = %d\n", $bit, $bit;
$bit = (-1 & 0x80000000) >> 31;
printf "masked: 0x%x = %d\n", $bit, $bit;
use integer;
print "\nuse integer\n";
$bit = -1 >> 31;
printf "unmasked: 0x%x = %d\n", $bit, $bit;
$bit = (-1 & 0x80000000) >> 31;
printf "masked: 0x%x = %d\n", $bit, $bit;
Output:
1:29 >perl 868_SoPW.pl
no integer
unmasked: 0x1ffffffff = 8589934591
masked: 0x1 = 1
use integer
unmasked: 0xffffffffffffffff = -1
masked: 0x1 = 1
1:29 >perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for MSWin32-x
+86-multi-thread-64int
:-(
Update: As BrowserUk observes below, masking removes the sign bit (in this case) only in perls built with 64-bit ints. For perls built with 32-bit ints, sn1987a’s observation does answer the OP’s question. (Moral for self: test, test, test!)
|