in reply to (jeffa) Re: Bitwise & with large numbers
in thread Bitwise & with large numbers
Actually Anonymonk has a valid point as this is a buffer overflow type bug. 4294967296 is a 33 bit integer, which is of course one bit more than 32. Perhaps you should meditate on this:
print "2**32 is: ", 2**32, "\n"; print <<TEXT; This is what we should have: 100000000000000000000000000000000 = 4294967296 011111111111111111111111111111111 = 4294967295 ---------------------------------------------- 000000000000000000000000000000000 = 0 But we get a buffer overflow like so, resulting in erroneous output: TEXT for (4294967295) { $a = dec2bin($_+1); $b = dec2bin($_); print "$a = ", $_ + 1, "\n", "$b = ", $_, "\n", "--------\n", dec2bin(($_+1) & $_), " = ", (($_+1) & $_), "\n\n"; } sub dec2bin { return unpack("B*", pack("N",shift)); }
I have no call for it personally but Math::BigInt might be useful.
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|