in reply to Re^3: converting binary to decimal
in thread converting binary to decimal
sub binary2decimal { defined $_[0] or return 0; my $B = $_[0]; $B =~ tr|01||cd; # Remove illegal chars $B =~ s/^0+//; # Remove preceding zeros my @BITS = split(//, $B); my $n = 0; my $copy1; my $copy2; my $copy3; foreach (@BITS) { $copy1 = $n; $copy2 = $n; $copy1 =~ tr/1-9/246802468/; $copy2 =~ tr/1-9/00001/; $n = (0 . $copy1 || $copy2 . $_); # This should be | not || $n =~ s/^0+(?=.)//; } return $n; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: converting binary to decimal
by LanX (Saint) on Jun 06, 2025 at 21:57 UTC | |
by LanX (Saint) on Jun 07, 2025 at 17:35 UTC | |
by tybalt89 (Monsignor) on Jun 07, 2025 at 18:03 UTC | |
by LanX (Saint) on Jun 07, 2025 at 23:11 UTC | |
by tybalt89 (Monsignor) on Jun 08, 2025 at 00:19 UTC | |
|