Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encoding problem

Status
Not open for further replies.

srudin

Programmer
Jan 1, 2002
32
CH
i understand that a byte array containing information encoded in unicode can (obviously!) not be decoded using, for example, ascii; the result is data "garbage". what i don't understand is why even a temporary conversion fails, or in other words, why the data "garbage" can not be reconverted back to unicode. let me make you an example:

byte[] b1 = byte array containing some unicode data
string s = Encoding.ASCII.GetString(b1);
byte[] b2 = Encoding.ASCII.GetBytes(s);
why is b2 not = b1?

i guess i'm missing something basic here about how encoding and byte-arrays work.
 
Unicode uses all 256 possible byte values. ASCII encoding only uses 0..127 -- anything 128 and up gets filtered out. This is per the definition of ASCII, which is a 7-bit encoding.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top