in reply to Base10 to Base2.
#!/usr/bin/perl print "Enter number (DECIMAL): ";chomp($dec=<STDIN>); while($dec){ $dec = int($dec); @base = reverse(split(/\^*/,$dec)); $intB = int($base[0]/2); $noIntB = $base[0]/2; if($intB eq $noIntB){$temp="0"} else{$temp="1"}push(@binary,$temp); $dec /= 2; if($dec < 1){last} } print "Binary : " . reverse(@binary),"\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Base10 to Base2.
by strider corinth (Friar) on Oct 21, 2002 at 18:45 UTC |