in reply to Re: How do I convert between decimal and binary?
in thread How do I convert between decimal and binary?
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:
which may not even be the optimal solution but is clearer, shorter and faster than your attempt.my $binary = sprintf "%b", $inputNumber; my @array = split //, $binary; # if you absolutely want the bits as a +n array
|
|---|