Convert char to byte
Hi
if I wrote
char c = some value and put in consideration UTF8;
byte b = (char)c;
What chances that I will loose data? and how can I convert without lossing data
Thanks
Hi
if I wrote
char c = some value and put in consideration UTF8;
byte b = (char)c;
What chances that I will loose data? and how can I convert without lossing data
Thanks
Hi,
A char is 16bit, byte 8 bit. You will loose data if you use this code.
Check these interesting posts to understand it better
http://discuss.joelonsoftware.com/default.asp?joel.3.151416.13
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=35689
HTH,
Suprotim Agarwal
byte[] b = System.Text.Encoding.UTF8.GetBytes(new char[] { c });
The array will contain between 1 and 4 bytes.