home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!ssd.intel.com!ichips!hfglobe!ibeam!gweil
- From: gweil@ibeam.intel.com (Garry Weil)
- Subject: Re: How to convert string to hex?
- Message-ID: <C1Fs2F.BB3@ibeam.intel.com>
- Organization: Multimedia Software Technology Group
- References: <C1FnMG.AMB@ibeam.intel.com>
- Date: Tue, 26 Jan 1993 00:59:02 GMT
- Lines: 23
-
- gweil@ibeam.intel.com (Garry Weil) writes:
-
- >How do I convert "Test" to 0x54 0x65 0x73 0x74 ?
-
- >Garry
- 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?
-
- BTW, I want to separate hex values with ",".
-
- Garry
-