Unicode Character

  • Thread starter Thread starter Ryu
  • Start date Start date
R

Ryu

Is there a way to get the convert a unicode character such as chinese
characters to byes? Everytime when I use Convert.toByte I will always get a
System.OverflowException "Value was either too big ot too small". Is it
because unicode characters require 16 bits? In that case how to I convert
the character to byes?
 
Hi Ryu,

Yes, unicode characters are two bytes in length and cannot be stored in a
single byte.
You can convert them to two bytes using

char c = (char)22345; // random character that may not even exist
byte[] b = Encoding.Unicode.GetBytes(new char[]{c});

An overload of GetBytes takes entire string and converts it to a byte
array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

encoding 1
The char datatype 5
Unicode in .NET 8
convert Int32 Unicode character code to its value 2
C# and encodings 30
Unicode character conversation 4
unicode textbox problem 9
size of a file and unicode 6

Back
Top