Thread binäre in dezimal
(16 answers)
Opened by Gast at 2005-11-13 15:19
[quote=esskar,13.11.2005, 15:38]chop ist nicht gut, da man ja immer das i der i-ten Stelle braucht.[/quote]
Wozu sollte man die Position im String benötigen? Zum Beispiel geht das hier wunderbar: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 use strict; use warnings; my $bin = <>; my $dec = 0; chomp $bin; $bin = reverse $bin; while (!((my $dig = chop $bin) eq '')) { $dec = 2*$dec + $dig; } print $dec . "\n"; When C++ is your hammer, every problem looks like your thumb.
|