0

i need a conversion code on c# to convert ASCII to Binary..

I'm doing a project on serial port and i need to display the received data in hex.. i have declared the received data as string. I used this code:

public static byte[] ConvertToBinary(string Rxstring)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            return encoding.GetBytes(Rxstring);
        }

p/s: Rxstring is the string variable that i declared for received data.

And when on the serial port testing, when i send ( for eg: #41 ) and my display must also be displaying #41. But on my display, it shows 'A'.Which it's outcome is not what i wanted. I think it's reading the received data in ASCII. Is it the code above don't seems to work for the conversion?

Thanks! =)

user1670247
  • 73
  • 1
  • 3
  • 9
  • 3
    http://stackoverflow.com/questions/623104/byte-to-hex-string – Nathan Dec 14 '12 at 02:11
  • 2
    41 hex is 'A' in ASCII. Can you be more clear with your question? Do you need to know why your receiver is taking that 41 and showing 'A' or are you unclear 'A' is the same as 0x41? – Peter Ritchie Dec 14 '12 at 04:37

0 Answers0