home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!paladin.american.edu!howland.reston.ans.net!usc!cs.utexas.edu!convex!convex!tchrist
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: How to convert string to hex?
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1993Jan26.172831.18300@news.eng.convex.com>
- Date: Tue, 26 Jan 1993 17:28:31 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <C1FnMG.AMB@ibeam.intel.com> <C1Fs2F.BB3@ibeam.intel.com>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 24
-
- From the keyboard of gweil@ibeam.intel.com (Garry Weil):
- :>How do I convert "Test" to 0x54 0x65 0x73 0x74 ?
- :Is there something better?
- :BTW, I want to separate hex values with ",".
-
- Legibility:
-
- while (<>) {
- chop;
- @a = unpack('C*', $_));
- for (@a) { $_ = sprintf("0x%x", $_); }
- print join(", ", @a), "\n";
- }
-
- Job security:
-
- perl -lpe '$_=join(", ",grep($_=sprintf("0x%02x",$_),unpack("C*", $_)))'
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
- "...this does not mean that some of us should not want, in a rather
- dispassionate sort of way, to put a bullet through csh's head."
- Larry Wall in <1992Aug6.221512.5963@netlabs.com>
-