I am reading RAW data from a source. This raw data is a sequence of Bytes. I store this sequence of Bytes into an array of Bytes that I define as following in VB.NET:
Dim frame() as Byte
so each element in the above array is in the range [0-255].
I want to encode each of these bytes into ASCII, UTF-8 and Unicode so I iterate over the byte array (frame) and perform below snippet code depending on the case:
ASCII:
For idxByte As Integer = 0 To Me.frame.Length - 1
txtRefs(idxByte).Text = Encoding.ASCII.GetString(String.Format("<{0}>", Encoding.GetString(frame, idxByte, 1))
Next
Note: txtRefs is an array of textboxes, and its length is the same as frame.
And similar for the other two encodings:
UTF-8:
For idxByte As Integer = 0 To Me.frame.Length - 1
txtRefs(idxByte).Text = Encoding.UTF8.GetString(String.Format("<{0}>", Encoding.GetString(frame, idxByte, 1))
Next
Unicode:
For idxByte As Integer = 0 To Me.frame.Length - 1
txtRefs(idxByte).Text = Encoding.Unicode.GetString(String.Format("<{0}>", Encoding.GetString(frame, idxByte, 1))
Next
ASCII and UTF8 encoding seems ok, but Unicode encoding seems it is not working or maybe I am not understanding Unicode encoding functionality at all...
For unicode I get below result by executing above loop. Is this correct?