473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Ascii to hex?

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.
Jul 19 '05 #1
4 27434
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;
Jul 19 '05 #2
"Bert" <gr*********@hotmail.com> wrote in message news:<cf*******************@bignews5.bellsouth.net >...
How do I convert an ascii to hex?


/opt/perl/bin/perldoc -q convert
Jul 19 '05 #3
In article <cf*******************@bignews5.bellsouth.net>, Bert
<gr*********@hotmail.com> 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.
Jul 19 '05 #4
Thank you all for your help. A newbie is smarter for your efforts. Thank
you.
"Bert" <gr*********@hotmail.com> wrote in message
news:cf*******************@bignews5.bellsouth.net. ..
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.

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
4
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII...
2
by: Martín Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
18
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
31
by: Claude Yih | last post by:
Hi, everyone. I got a question. How can I identify whether a file is a binary file or an ascii text file? For instance, I wrote a piece of code and saved as "Test.c". I knew it was an ascii text...
24
by: ChaosKCW | last post by:
Hi I am reading from an oracle database using cx_Oracle. I am writing to a SQLite database using apsw. The oracle database is returning utf-8 characters for euopean item names, ie special...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.