How to convert string to asci and asci to hex
-
-
I need to display data in Hexa. I will be geting data in asci which will be getting stored in string and i need to convert theis string to hexa and display it in textbox. Ex Receiving "50 3F 52 40" as string Need to covert in to hex as -> "P ? R @"
Your example seems to do the opposite of what you want. Simplest solution might be to use String.Format. What have you tried? If you post code then you're more likely to get a helpful response. :)
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis
-
I need to display data in Hexa. I will be geting data in asci which will be getting stored in string and i need to convert theis string to hexa and display it in textbox. Ex Receiving "50 3F 52 40" as string Need to covert in to hex as -> "P ? R @"
-
Your example seems to do the opposite of what you want. Simplest solution might be to use String.Format. What have you tried? If you post code then you're more likely to get a helpful response. :)
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis
-
This is the code snip i am working on...kindly look and let me know the answer
MessageBox.Show(this.listBox1.Text.ToString());
this.txtToSend.Text = string.Format("{0:X}", "3F 50");i must get an output as "? P" in Hex
You seem to be confused about what Hex means. :) This is Hex (well a string of Hex characters):
pallaka wrote:
3F 50
And this is (printable) ASCII or whatever the encoding is.
pallaka wrote:
? P
If you have a string of Hex characters separated by spaces (which is what your example shows) I suggest using Split on txtToSend.Text to get an array and then loop through the array to output the chars. You will need convert the array entries to numeric and then the numeric to char.
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis
-
Don't know if this will help http://www.testingreflections.com/node/view/5635[^]
-
It is doing opposite to me... i mean if i send "?" it is giving output as "3F" I agree i really confused...3F is my Hex value and i need to convert to asci I need fully opposite way..... I need to send "3F" and i should get result as "?"
-
I need to display data in Hexa. I will be geting data in asci which will be getting stored in string and i need to convert theis string to hexa and display it in textbox. Ex Receiving "50 3F 52 40" as string Need to covert in to hex as -> "P ? R @"
Hi, The solution will take some 10 lines of code including an explicit loop. here are a few things you will need: 1. split the input string (which is a hex string) into parts, each holding 2 hex digits; you could use string.Split() or string.Substring() 2. convert a 2-digit hex string to its numeric value; you need int.Parse() or int.TryParse() with some options 3. convert that number to an ASCII character; you might try that with a (char) cast, the safer way would use an Encoding method. 4. concatenate all the results; either use a string operator or StringBuilder class. If all this is too much for you, this is what you should have done: http://lmgtfy.com/?q=convert+hex+string+to+ASCII[^] :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Ah i think this will work then. When i try it prints out the correct ascii number label1.Text = Convert.ToInt32("3F", 16).ToString(); may not be the most efficient way.
It Prints the value 63. But i need "?" how can i convert 63 to symbol representation. You can have a look in www.asciitable.com
-
It Prints the value 63. But i need "?" how can i convert 63 to symbol representation. You can have a look in www.asciitable.com