# Thread: Another ascii question....

1. Member
Join Date
Feb 2009
Posts
2
Rep Power
0

## Another ascii question....

Hi guys,

Firstly I would like to say hello as this is my first post.

Secondly, I would like to apologise for this thread about ascii, but its bothering me.

I've written this:

byte[] x = message.getBytes();
for(int i = 0; i < x.length; i++)
{
mess += Integer.toString(x[i]);
}

which takes a String parameter and returns the ascii value, so, "A" would return 65, "AA" would return 6565 etc

My question is this: Taking the latter of the two examples above, how would I return 6565 to "AA".

It's quite late at night to be dealing with this but I'm stuck and cant sleep so thought I would give it a go with no success at this point in time.

I look forward to anyone who can shed some light on this.

Regards

Ric

2. you'll need to change the string into a byte, then typecast it into a char.
Java Code:
```    String msg = "65";
char c = (char) Byte.parseByte(msg);
System.out.println(c);```
in your case, i would put that in a loop and pick out every two digits.

3. I don't think it will work with base 10 numbers as some ascii numbers are 3 digits long, and without spaces or something else to allow parsing of the string, it would be easy to get out of phase. One solution is to use hex Strings which will be 2 digits, another is to separate each number by a space.

4. you're right, i was thinking of hex. but 65 is dec.
so you could use hex or write a checker.
Codes 33 to 126, known as the printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols.
so check the first digit, if its 3 or above then take two digits. if its one, then take 3 digits.
e.g.: 33366578125122 would be split into
33, 36, 65, 78, 125, 122.
and then typecast into char.
Last edited by angryboy; 02-19-2009 at 05:42 AM.

5. Member
Join Date
Feb 2009
Posts
2
Rep Power
0
Thank you very much for your quick replies.

It must be one of those things where you are looking at something for a very long time, but I still cannot do it!

I have amended:

mess += Integer.toString(x[i]);

to

mess += Integer.toString(x[i]).toUpperCase();

so that most values only consist of 2 values.

But I cannot loop over 2 characters at a time and change them back to chars :(

It's driving me mad!

6. how did you decode the digits? lets see the code.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•