Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1071265]
[LanX]: "DH" eq "Dumb Homies "?
[shmem]: no, no previous, and python just accepts that.
[LanX]: HA ... fun! =)
[LanX]: Py2 or 3 ?
[shmem]: moment... lemme see...
[shmem]: Python 2.7.9
[shmem]: but! perl4 doesn't suck.
[LanX]: better try 3

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2018-03-20 18:31 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (257 votes). Check out past polls.