Seems to me it would be cheaper to actually convert the number.
sub test { my ($num, $base) = @_; while ($num > 0) { my $digit = $num % $base; return 0 if $digit > 1; $num = ($num - $digit)/$base; } return 1; }
Takes at most floor(logb(n)) loop passes, just like what you were attempting.
In reply to Re: Can It Be Written In Base X With Only 1s And 0s
by ikegami
in thread Can It Be Written In Base X With Only 1s And 0s
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |