Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: binary converter

by Jenda (Abbot)
on Apr 23, 2013 at 12:20 UTC ( #1030121=note: print w/ replies, xml ) Need Help??

in reply to Re: binary converter
in thread binary converter

The position shoul be digit :-)

In either case you do not need the index nor the ** operator.

my @digit = reverse split //, $bin; my $num = 0; for my $bit (@digit) { $num = $num * 2 + $bit; } print "\n$num\n";

Enoch was right!
Enjoy the last years of Rome.

Comment on Re^2: binary converter
Select or Download Code
Replies are listed 'Best First'.
Re^3: binary converter
by Limbic~Region (Chancellor) on Apr 23, 2013 at 17:25 UTC
    Or digit should have been position.

    I wouldn't have written the code I did for myself - it was intended to be more instructional since the OP indicated not understanding the for loop. I guess I should have paid closer attention (updated now). Thanks!

    Cheers - L~R

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2016-02-14 02:35 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (454 votes), past polls