简体   繁体   中英

Converting bytecode back to char in c# win. form

I have written a piece of code which returns byte code of any character which is shown below

string ByteCodeValue = Convert.ToString((char)65533, 2).PadLeft(8, '0');
//which returns value "1111111111111101"

but when i try to do it vice-versa it does not work and gives an exception as follows " Value was either too large or too small for an unsigned byte. "

char OldChar= (char)Convert.ToByte("1111111111111101", 2);

Please tell me where i am going wrong?

Thanks in advance

You're converting 16-bit unsigned value, not byte (8 bit). See this doc . Try using:

 var oldChar = (char)Convert.ToUInt16(ByteCodeValue,2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM