Results 1 to 6 of 6
Thread: Another ascii question....
- 02-19-2009, 01:03 AM #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
- 02-19-2009, 03:10 AM #2
you'll need to change the string into a byte, then typecast it into a char.
in your case, i would put that in a loop and pick out every two digits.Java Code:String msg = "65"; char c = (char) Byte.parseByte(msg); System.out.println(c);USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
-
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.
- 02-19-2009, 05:33 AM #4
you're right, i was thinking of hex. but 65 is dec.
so you could use hex or write a checker.
so check the first digit, if its 3 or above then take two digits. if its one, then take 3 digits.Codes 33 to 126, known as the printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols.
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.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 02-19-2009, 11:35 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!
- 02-20-2009, 01:38 AM #6
how did you decode the digits? lets see the code.
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Similar Threads
-
I need help with ascii characters
By Grandon in forum EclipseReplies: 17Last Post: 11-08-2008, 02:12 AM -
Ascii code.........
By Somitesh Chakraborty in forum New To JavaReplies: 6Last Post: 11-04-2008, 05:32 PM -
ASCII to EBCDIC conversion
By satish kumar in forum Advanced JavaReplies: 1Last Post: 08-13-2008, 01:59 PM -
Getting ASCII codes of character
By gapper in forum New To JavaReplies: 1Last Post: 02-02-2008, 09:42 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks