Results 1 to 9 of 9
- 06-14-2011, 10:12 AM #1
help - Ascii to hex and hex to ascii conversion
Hi friends,
I need to convert the hex data to ascii java.. commonly, the Hex values are 0 (00) to 127 (7F) are converted and printed correctly, i need to print the value from 128 (80) - 255 (FF)..
How to convert the value.. I tried lot.. any one can help me..
- 06-14-2011, 10:53 AM #2
What have you tried, and what were the results?
- 06-14-2011, 11:35 AM #3
private static String asciitohex(String data)
{
char[] chars = data.toCharArray();
StringBuffer hex = new StringBuffer();
StringBuffer hexval = new StringBuffer();
for(char ch : chars)
{
hex.append(Integer.toHexString(ch));
}
return hexval.toString();
}
here is my code friend to convert ascii to hex,
it converts 'R' to '52'..
some it will shows 2018, 201C, 2026, FFFD, 153, 178...
How can i get know the ascii values for these hex values.
- 06-14-2011, 11:39 AM #4
Do you have some examples of what is converted to the longer hex values?
- 06-14-2011, 11:44 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-14-2011, 11:48 AM #6
i use these codes to my serial port connection ..
am sending the hex value 31... and the serial port will show result as 1..
then i convert the ascii value to 31..
like these,
32 - 2
33 - 3
41 - A
if i send '95' i will get the hex value 2022
for 96 i will get 2013.. the conversion problem occur in hex values from 80 to 9F...
- 06-14-2011, 11:58 AM #7
As said above, char is coded in unicode, not in ASCII. While the lower part of unicode is identical to ASCII (00-7F, hex-wise), extended ASCII does not translate to unicode in the same way. That's why this happens.
- 06-14-2011, 12:04 PM #8
Ok friend, then how can i convert the extended ASCII values to hex..
give me step of help.. to write the program for that conversion
- 06-14-2011, 12:53 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
Don't bother about any conversion: as long as you only use the characters that are present on a US keyboard you can send them as is to your device, e.g.
kind regards,Java Code:sendToDevice('1'); // sends hexadecimal value 31 sendToDevice('A'); // sends hexadecimal value 41 ...
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
How to convert BCD to ascii
By slavicp in forum Advanced JavaReplies: 2Last Post: 04-05-2011, 11:54 AM -
Another ascii question....
By akira220984 in forum New To JavaReplies: 5Last Post: 02-20-2009, 01:38 AM -
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


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks