View Single Post
Old 07-07-2004, 09:51 AM   #129
Unregistered
Nameless Being
 
I am actually working on a perl-version, too, right now.
I ran into the problem you described with the first test ...
the overflowing with bigger numbers and bitwise operations seems not to work.
I actually don't have a clue about all these basical things, I'm doing cgi-scripts most of the time. Anyhow, enough excuses. I think the problem can be solved by not using the bitwise operators on the big ints but simply prepare the ints to behave like in php or bash: for example
Code:
sub bitleft
{
	my $first = shift;
	my $second = shift;
	my $max = 4_294_967_296;
	my $special = 1 if($first > $max || $second > $max);
	$first = $first - $max if($first > $max);
	$second = $second - $max if($second > $max);
	if($special == 1)
	{
		return ($first << $second);
	}
	my $result = $first << $second;
	return -($max - $result);
}
where
$a << $b would be bitleft($a, $b);
it more or less works, but does not in all subs deal with signs correctly (eg. the xor-one has a problem with too big negative numbers). drop me a line at jan@delinquent.SPAMISBAD.de and I'll be happy to send you the code I got so far. remove the SPAMISBAD, of course
  Reply With Quote