Hi,
I'm going mad! I'm trying to use some smallish integers as bit vectors.
Can anyone tell me why the following produces different (erroneous)
results under MacPerl to those on other Unix perls I have access to?
use integer;
$a = 0x2a | 0; # 42 = 2 + 8 + 32; 106 = 2 + 8 + 32 + 64
print "$a\n";
$a1 = 0x01; $count = 0;
while (($a > 0) && ($count < 20)) {
print (($a & $a1));
print ", $a, $a1, $count\n";
if (($a1 & $a)>0) {
print "We have a $a1\n";
$a -= $a1;
}
$a1 <<= 1;
$count++;
}
print "We went through $count times\n";
produces in MacPerl 5.2.0r4 on an iMac running system 9.1:
42
0, 42, 1, 0
2, 42, 2, 1
We have a 2
0, 40, 4, 2
We have a 4
0, 36, 8, 3
0, 36, 16, 4
32, 36, 32, 5
We have a 32
0, 4, 64, 6
We have a 64
We went through 7 times
and on either 'This is perl, version 5.003 with EMBED
built under dec_osf at Apr 18 1997 12:24:24' or
'This is perl, version 5.005_03 built for sun4-solaris'
42
0, 42, 1, 0
2, 42, 2, 1
We have a 2
0, 40, 4, 2
8, 40, 8, 3
We have a 8
0, 32, 16, 4
32, 32, 32, 5
We have a 32
We went through 6 times
Really weird!
Rod
--
Rod Van Cooten, Phone: +61 3 8344 6840
Manager, LAN Server Group, Client Services,
Information Division, Fax: +61 3 9347 4803
University of Melbourne, Email: [EMAIL PROTECTED]
Grattan St, Parkville 3010. VIC. Australia