|
Posted by benkasminbullock@gmail.com on March 18, 2008, 10:57 pm
Please log in for more thread options On Mar 18, 8:37 pm, "Venkatesh can....can..."
> How to convert hexadecimal number to binary in perl ??
#! perl
use warnings;
use strict;
# Create the stuff for matching
my $matches = "0123456789ABCDEF";
my %hex2bin;
for (my $i=0;$i<16;$i++) {
$hex2bin=int($i/8).int(($i/4)%2).int(($i/
2)%2).int($i%2);
}
# Now test
my $hex_string = "1234BAad12345";
print "Before: $hex_string\n";
$hex_string =~ s/([$matches])/$hex2bin/gi;
print "After: $hex_string\n";
|