hex to binary

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
How to convert hexadecimal number  to binary in perl ??

Re: hex to binary

Venkatesh can....can... wrote:

perldoc -f hex

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html

Re: hex to binary

You must have missed the current discussion titled "decrease MAC".
There are no hexadicimal numbers but only numbers in hexadecimal
representation. And the same for binary.
So, use hex() to convert the string into a number and then sprintf()  to
convert the number into a binary representation as string.

jue

Re: hex to binary

On Mar 18, 8:37 pm, "Venkatesh can....can..."

#! 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";