Computing.Net > Forums > Programming > Hex to ascii program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Hex to ascii program

Reply to Message Icon

Name: abdi
Date: June 10, 2002 at 07:13:36 Pacific
Comment:

Hi friends,
I was working on aprogram that takes 16 Hex characters and converts to 8-ascii characters
the program generates large numbers which are in bytes, but somehow I cannot change to correponding Ascii characters. it generates
numbers such 166,239... numbers less than 255.

the function calls Convert() which returns the decimal of hex character

Can anyone help me how I can achieve the desired Ascii chars ? the code is commented to be able to read.

I am really in need for help to get this wright.

Thanks in advance.
/* prtotypes */
typedef unsigned char ByteType ;
int Convert(ByteType val );

ByteType ASCIZ(ByteType *Addr);

ByteType ASCIZ(ByteType *Addr)
{
int i, v1, v2;
ByteType a1, a2, v,y;


/* Convert 16-HEXA-character key to be 8-ASCII-character key. */
for (i = 0; i < 8; i++)
{
a1 = *Addr++;
if (i == 7)
a2 = *Addr;
else
a2 = *Addr++;
/* Convert two HEXA characters into their decimal value. */
v1 = Convert(a1);
v2 = Convert(a2);


/* Convert the two decimal value to be one ASCII character. */
v = ((v1 * 16) + v2);
}

return v;
}




Sponsored Link
Ads by Google

Response Number 1
Name: cup
Date: June 11, 2002 at 01:22:51 Pacific
Reply:

The ASCII range is from 0 to 127, of which 0 to 31 and 127 are non printing characters, well sort of.

Problem 1: how are you intending to represent a character over 128 unless you go for an extended character set. I don't know if there is a standard extension.

Problem 2: if you are printing them, how are you going to print the non-printable characters. Are you printing them?

You could go for the uuencode type strategy which restricts the set. The result of this is that you will need more than 8 chars for 16 digits.


0
Reply to Message Icon

Related Posts

See More


Asp session how to convert .cgi into ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Hex to ascii program

Java need code: hex to Ascii www.computing.net/answers/programming/java-need-code-hex-to-ascii/3727.html

algoritm to convert hex to bcd, plz www.computing.net/answers/programming/algoritm-to-convert-hex-to-bcd-plz/14072.html

Binary to ASCII conv. in assembly www.computing.net/answers/programming/binary-to-ascii-conv-in-assembly/12420.html