1

For some reason when I type "Encoding." in to VS all there is UTF8, Equals, and ReferenceEquals. Does anyone know why I can't use ASCII? I need to convert serial data from bytes[] to Char[] or String.

I'm using .net framework 4.1

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Justin Gardner
  • 605
  • 2
  • 9
  • 17

2 Answers2

1

This worked for me when I created a UDP message sender/receiver.

using System.Text;

//converts string/char into ASCII
byte[] encoding = System.Text.ASCIIEncoding.ASCII.GetBytes("Hello, World!");

//converts ASCII into string
Console.Write(Encoding.ASCII.GetString(encoding));
William Lew
  • 485
  • 6
  • 17
  • I gen an error saying that ASCIIEncoding isn't under System.Text and perhaps I'm missing a resource – Justin Gardner Mar 12 '14 at 21:55
  • That's odd, ASCIIEncoding seems to be part of mscorlib - http://msdn.microsoft.com/en-us/library/system.text.asciiencoding(v=vs.110).aspx – dsolimano Mar 13 '14 at 16:01
0

ASCII encoding is subsumed by UTF-8 -- You should not be attempting to use ASCII encoding in network/Bluetooth transport systems. ASCII is a legacy encoding (used extensively in RS-232 communications) and does not use the MSB -- so a value of 160 -- is not possible in ASCII...127 is the maximum value available in ASCII.

You can use ASCII all day long in your sandbox, but -- you cannot use it on a wired/wireless transport.

Use UTF-8 instead.

jinzai
  • 436
  • 3
  • 9