Click here to get back home

hex to binary

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
hex to binary Venkatesh can....can... 03-18-2008
|--> Re: hex to binary Josef Moellers03-18-2008
`--> Re: hex to binary benkasminbulloc...03-18-2008
Posted by Venkatesh can....can... on March 18, 2008, 7:37 am
Please log in for more thread options
How to convert hexadecimal number to binary in perl ??

Posted by Josef Moellers on March 18, 2008, 8:04 am
Please log in for more thread options
Venkatesh can....can... wrote:
> How to convert hexadecimal number to binary in perl ??

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

Posted by Jürgen Exner on March 18, 2008, 12:28 pm
Please log in for more thread options
>How to convert hexadecimal number to binary in perl ??

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

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

Similar ThreadsPosted
Help: Binary June 27, 2007, 10:39 am
hex to binary conversion November 29, 2004, 4:00 pm
Binary compatibility 5.8.0 -> 5.8.7 June 8, 2005, 6:40 pm
Net::FTP - Binary mode November 13, 2005, 2:42 pm
Binary to Decimal for >2**32 November 14, 2007, 3:45 pm
Binary files in PERL? November 7, 2004, 2:31 pm
FAQ 2.2: How can I get a binary version of Perl? January 5, 2005, 12:03 am
FAQ 2.2 How can I get a binary version of Perl? January 9, 2005, 6:03 pm
Problem with binary numbers February 6, 2005, 3:59 am
FAQ 2.2 How can I get a binary version of Perl? May 16, 2005, 5:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap