Just for the record, the "mathmatical error" [sic] applies to your use of >>
which is the right bit-shift operator, where each bit is shifted to the right by n places (in digit >> n):
my $one = 8;
my $two = 2;
# right shift 8 by 2 places
# 00001000 (binary 8) becomes 00000010 (binary 2)
print $one >> $two; # prints 2