Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > hex to binary

Reply
Thread Tools

hex to binary

 
 
Venkatesh can....can...
Guest
Posts: n/a
 
      03-18-2008
How to convert hexadecimal number to binary in perl ??
 
Reply With Quote
 
 
 
 
Josef Moellers
Guest
Posts: n/a
 
      03-18-2008
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      03-18-2008
"Venkatesh can....can..." <> wrote:
>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
 
Reply With Quote
 
benkasminbullock@gmail.com
Guest
Posts: n/a
 
      03-19-2008
On Mar 18, 8:37 pm, "Venkatesh can....can..."
<venkatesh.sou...@gmail.com> wrote:
> 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{substr($matches,$i,1)}=int($i/.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{uc($1)}/gi;
print "After: $hex_string\n";
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hex string to hex value tim Python 8 11-23-2005 06:27 PM
[Fwd: Re: hex string to hex value] tim Python 2 11-23-2005 07:18 AM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
hex value in string back to real hex value jack Python 4 09-08-2004 07:11 AM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57