in reply to Reading Binary
I did not get the impression that the OP was interested in doing actual binary to decimal conversion although jwkrahn's suggestion of: $decimal = oct( "0b$input" ); looks like a "winner" to me in the case of ASCII strings.#!/usr/bin/perl -w use strict; my @ltrs = qw (A B C D); my $num = "0101"; print "$num=>"; my $i =0; foreach my $bit (split(//,$num)) { print $ltrs[$i] if $bit; $i++; } print "\n"; # prints: 0101=>BD
I would like to hear more about the application if these bits or combinations of bits represent something other than just a number. I probably would have some suggestions in that event, but want to hear more before running off on a tangent.
|
|---|