Perl: Decimal Number to Binary Number - by Eun Bae Kim (11/25/2018)
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
  
use strict;

my $iOriginalNum = 2000;
my $iUnit = 64;


my $iNum  = $iOriginalNum;
my $sRemainders = "";

while($iNum >= $iUnit) {
	my $iRemainder = $iNum % $iUnit;
	my $iQuotient  = ($iNum - $iRemainder) / $iUnit;

	$sRemainders = $iRemainder." ".$sRemainders;
	$iNum = $iQuotient;
	if ($iNum < $iUnit) {
		$sRemainders = $iNum." ".$sRemainders
	}
}

print $iOriginalNum."\t==> ".$sRemainders."\n";