Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Ascii to hex?

Reply
Thread Tools

Ascii to hex?

 
 
Bert
Guest
Posts: n/a
 
      10-09-2003
How do I convert an ascii to hex? I want the hex stored in a variable, not
just printed out.
For example,
my testchars = 'CICS003'
How do I store that value in hexchars?
I know this is basic, but it eludes me...
Thanks from a newbie.


 
Reply With Quote
 
 
 
 
Purl Gurl
Guest
Posts: n/a
 
      10-09-2003
Bert wrote:

(snipped)

> How do I convert an ascii to hex?


Have you considered research and reading?

My experience is learning is not painful.
However, lazy people are a pain.

http://www.google.com/search?hl=en&i...ii+to+hex+perl


Purl Gurl
--
Size Does Matter
http://www.purlgurl.net/~godzilla


#!perl

@Hex = unpack("C*", "Purl Gurl Rocks");

print "@Hex\n";

$ascii = pack("C*", @Hex);

print $ascii;
 
Reply With Quote
 
 
 
 
Roy Johnson
Guest
Posts: n/a
 
      10-09-2003
"Bert" <(E-Mail Removed)> wrote in message news:<cf4hb.60753$(E-Mail Removed) >...
> How do I convert an ascii to hex?


/opt/perl/bin/perldoc -q convert
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      10-09-2003
In article <cf4hb.60753$(E-Mail Removed)>, Bert
<(E-Mail Removed)> wrote:

> How do I convert an ascii to hex? I want the hex stored in a variable, not
> just printed out.
> For example,
> my testchars = 'CICS003'
> How do I store that value in hexchars?
> I know this is basic, but it eludes me...
> Thanks from a newbie.
>
>


You can use ord to get the numerical value of an ascii character and
sprintf "%x" to generate the hexadecimal representation of that number:

#!/opt/perl/bin/perl
use strict;
use warnings;

my $testchars = 'CICS003';
my $hexchars = '';
foreach my $c (split(//,$testchars)) {
$hexchars .= sprintf "%x", ord($c);
}
print "$hexchars\n";

__OUTPUT__
43494353303033

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 
Reply With Quote
 
Bert
Guest
Posts: n/a
 
      10-13-2003
Thank you all for your help. A newbie is smarter for your efforts. Thank
you.


"Bert" <(E-Mail Removed)> wrote in message
news:cf4hb.60753$(E-Mail Removed). ..
> How do I convert an ascii to hex? I want the hex stored in a variable, not
> just printed out.
> For example,
> my testchars = 'CICS003'
> How do I store that value in hexchars?
> I know this is basic, but it eludes me...
> Thanks from a newbie.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex with ASCII and non-ASCII chars TOXiC Python 5 01-31-2007 04:48 PM
[FR/EN] how to convert the characters ASCII(0-255) to ASCII(0-127) Alextophi Perl Misc 8 12-30-2005 10:43 AM
Wow, ascii's gone BERSERK! Poly-poly man Firefox 2 03-25-2005 01:37 PM
Hex and ASCII Keys -TC- Wireless Networking 0 06-20-2004 06:18 PM
routine/module to translate microsoft extended ascii to plain ascii James O'Brien Perl Misc 3 03-05-2004 04:33 PM



Advertisments