home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ascent!ascent!paul
- From: paul@ascent.com (Paul Foley)
- Subject: Re: How to convert string to hex?
- In-reply-to: gweil@ibeam.intel.com's message of Tue, 26 Jan 1993 00:59:02 GMT
- Message-ID: <PAUL.93Jan26141847@MountRushmore.ascent.com>
- Date: 26 Jan 93 14:18:47
- References: <C1FnMG.AMB@ibeam.intel.com> <C1Fs2F.BB3@ibeam.intel.com>
- Organization: Ascent Technology, Inc., Cambridge Massachusetts
- Lines: 30
-
- In article <C1Fs2F.BB3@ibeam.intel.com> gweil@ibeam.intel.com (Garry Weil) writes:
-
- >How do I convert "Test" to 0x54 0x65 0x73 0x74 ?
-
- The best I have come up with, so far is the following:
-
- #!/usr/local/bin/perl
- while (<>) {
- $_ = reverse $_ ;
- for ($i=1; $i < length($_);) {
- $c = chop ;
- printf "0X%x", ord $c ;
- printf ", " unless $i == length ($_) ;
- }
- }
- print "\n" ;
-
- Is there something better?
-
- How about ...
-
- #!/usr/local/bin/perl
- while (chop($line = <>)) {
- print join(', ', grep(s/(.*)/sprintf("0x%x", ord($1))/e, split(/ */, $line))), "\n";
- }
- --
- --------------------------------------------------------------------------------
- Paul Foley Ascent Technology Inc.
- Development Engineer 64 Sidney St. Cambridge, MA 02139
- paul@ascent.com (617) 225-0850 x315
-