[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference 7.286::perl

Title:Perl
Notice:PERL, the Pathologically Eclectic Rubbish Lister
Moderator:PLUGH::needle
Created:Thu Jun 02 1994
Last Modified:Thu May 15 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:56
Total number of notes:132

56.0. "Converting number to hex "bytes"" by MGB.RKG.DEC.COM::GILLOTT (Mark Gillott, 831-3172 (rkg)) Mon May 12 1997 16:51

I'm attempting  to write my first perl script and I need to convert a number
into  a  series of hex digits.  Suppose I have a number, 60000, I want to be
able  to convert it to hex - 0000EA60 - and then take the hex value apart to
generate 4 separate values, "00", "00", "EA" and "60".  I can use sprintf to
generate  the  value  as a hex string, but I can't seem to figure out how to
split the string up.  Any ideas?. 

Thanks, 

Mark
T.RTitleUserPersonal
Name
DateLines
56.1You can use sprintf (...)BRSSWS.BRO.DEC.COM::LEENJaak Leen, TP/IM Support Belgium 856-8738Tue May 13 1997 21:028
Here we go:

($x1,$x2,$x3,$x4) = ( sprintf("%0.8X",60000) =~ /(..)(..)(..)(..)/);
print "$x1 $x2 $x3 $x4\n";

Regards,

Jaak
56.2mgb.rkg.dec.com::GILLOTTMark Gillott, 831-3172 (rkg)Thu May 15 1997 14:054
Thanks.  I  ended  up using a shift & mask construct, but .1 is much better.
Where can I find out more on the "(..)" thing?. 

Mark
56.3Far More Than Everything You've Ever Wanted to Know About...BRSSWS.BRO.DEC.COM::LEENJaak Leen, TP/IM Support Belgium 856-8738Thu May 15 1997 19:087
ftp://ftp.digital.com/pub/plan/perl/CPAN/doc/FMTEYEWTK/index.html

look at 'What Makes Perl's Regular Expressions Dynamite'

Regards,

Jaak