in reply to Re: Base10 to Base2.
in thread Base10 to Base2.
I think tadman's answer in the previous thread was more elegant (but apparently it only works in 5.6 or higher):print "Enter a decimal number: "; chomp( $decimal = <STDIN> ); $binary = ''; while( $decimal ){ $binary = $decimal%2 . $binary; $decimal = int( $decimal/2 ); } print STDOUT $binary;
|
|---|