After I wrote the program, I came to PerlMonks and saw that there was already a way to do this, obviously better, but I kind of feel proud of this script since I made it all on my own. So ...
#!/usr/bin/perl # Implementation: perl *.pl BINARY_NUM my @inputr = reverse split(//, shift); my $output = 0; for (0 .. @inputr-1) { $output += ($inputr[$_] * (2**$_)); } print "$output\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Binary to Decimal (zdog's way)
by merlyn (Sage) on Aug 31, 2000 at 14:56 UTC | |
|
Re: Binary to Decimal (zdog's way)
by I0 (Priest) on Dec 30, 2000 at 18:44 UTC |