Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Answer: How do I convert between decimal and binary?

by morgon (Priest)
on Jan 20, 2014 at 03:57 UTC ( [id://1071265]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I convert between decimal and binary?
in thread How do I convert between decimal and binary?

This should not appear as "categorized answers" as it may mislead others.

Apart from the fact the you don't do any error-handling (e.g. your program does not work for negative numbers, but does not raise an error) the implementation is questionable.

If your printing of intermediate values is not considered an essential feature you could e.g. simply do this:

my $binary = sprintf "%b", $inputNumber; my @array = split //, $binary; # if you absolutely want the bits as a +n array
which may not even be the optimal solution but is clearer, shorter and faster than your attempt.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071265]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found