Files
devops/perl/Examples/Chap5/binary-2
2025-09-17 16:08:16 +08:00

20 lines
248 B
Plaintext

###
### binary2
###
## Chapter 5 section 4.2
sub binary {
my ($n, $RETVAL) = @_;
$RETVAL = "";
while (1) {
my $k = int($n/2);
my $b = $n % 2;
$RETVAL = "$b$RETVAL";
return $RETVAL if $n == 0 || $n == 1;
$n = $k;
}
}