hex to binary

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

Threaded View
How to convert hexadecimal number  to binary in perl ??

Re: hex to binary

Venkatesh can....can... wrote:
Quoted text here. Click to load it

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

Quoted text here. Click to load it

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.


Re: hex to binary

On Mar 18, 8:37 pm, "Venkatesh can....can..."
Quoted text here. Click to load it

#! perl
use warnings;
use strict;

# Create the stuff for matching

my $matches = "0123456789ABCDEF";
my %hex2bin;
for (my $i=0;$i<16;$i++) {

# Now test

my $hex_string = "1234BAad12345";
print "Before: $hex_string\n";
$hex_string =~ s/([$matches])/$hex2bin/gi;
print "After: $hex_string\n";

Site Timeline