for($a = 0; $a < ($n % $SIZE); $a++) { $carry = 0x1 & $p; #extract least significant bit $p >>= 1; #shift $p by one spot to the right if($carry == 1) #to rotate in a leading 1 { my $or = 2 ** ($SIZE - 1); #$SIZE is # of bits in $p print "OR: $or\n"; print "pre|: $p. carry: $carry\n"; $p |= $or; #bitwise or in $or to add the leading 1 to $p } print "$a-$p\n"; }