home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 7988 < prev    next >
Encoding:
Text File  |  1993-01-26  |  826 b   |  34 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!ssd.intel.com!ichips!hfglobe!ibeam!gweil
  3. From: gweil@ibeam.intel.com (Garry Weil)
  4. Subject: Re: How to convert string to hex?
  5. Message-ID: <C1Fs2F.BB3@ibeam.intel.com>
  6. Organization: Multimedia Software Technology Group
  7. References: <C1FnMG.AMB@ibeam.intel.com>
  8. Date: Tue, 26 Jan 1993 00:59:02 GMT
  9. Lines: 23
  10.  
  11. gweil@ibeam.intel.com (Garry Weil) writes:
  12.  
  13. >How do I convert "Test" to 0x54 0x65 0x73 0x74 ?
  14.  
  15. >Garry
  16. The best I have come up with, so far is the following:
  17.  
  18. #!/usr/local/bin/perl
  19. while (<>) {
  20.     $_ = reverse $_ ;
  21.     for ($i=1; $i < length($_);) {
  22.         $c = chop ;
  23.         printf "0X%x", ord $c ;
  24.         printf ", " unless $i == length ($_) ;
  25.     }
  26. }
  27. print "\n" ;
  28.  
  29. Is there something better?
  30.  
  31. BTW, I want to separate hex values with ",".
  32.  
  33. Garry
  34.