home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!mcsun!sunic!aun.uninett.no!nuug!nntp.uio.no!nntp.uio.no!aas
- From: aas@rosmer.nr.no (Gisle Aas)
- 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: <AAS.93Jan26093556@rosmer.nr.no>
- Sender: news@ulrik.uio.no (Mr News)
- Nntp-Posting-Host: rosmer.nr.no
- Reply-To: Gisle.Aas@nr.no
- Organization: Norwegian Computing Centre, Oslo, Norway
- References: <C1FnMG.AMB@ibeam.intel.com> <C1Fs2F.BB3@ibeam.intel.com>
- Date: Tue, 26 Jan 1993 08:35:56 GMT
- Lines: 25
-
- In article <C1Fs2F.BB3@ibeam.intel.com> gweil@ibeam.intel.com (Garry Weil) writes:
- > >How do I convert "Test" to 0x54 0x65 0x73 0x74 ?
- >
- > Is there something better?
- >
- > BTW, I want to separate hex values with ",".
-
- How about:
- perl -e 'for (split(//,"Test")) {
- $a .= sprintf("0x%x,", ord)
- }
- chop $a; print $a'
-
- or
-
- #!/usr/local/bin/perl
- while (<>) {
- chop;
- print join(',', grep($_="0x".$_,unpack("H2" x length, $_))), "\n";
- }
- --
- Gisle Aas | snail: Boks 114 Blindern, N-0314 Oslo, Norway
- Norsk Regnesentral | X.400: G=Gisle;S=Aas;O=nr;P=uninett;C=no
- voice: +47-2-453561 | inet: Gisle.Aas@nr.no
-
-