Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Byte to String to byte conversion puzzling error

Could anyone please help spot the error? Here's the code:

   byte[] oriBytes = { 0xB0, 0x2D };                       // oriBytes -> 0xB0, 0x2D
   string oriInStr = Encoding.ASCII.GetString(oriBytes);   // oriInStr ->   "?-"
   oriBytes = Encoding.ASCII.GetBytes(oriInStr);           // oriBytes -> 0x3F, 0x2D

I can't get back the original bytes values of 0xB0, 0x2D.

like image 869
sam byte Avatar asked Dec 11 '22 02:12

sam byte


1 Answers

0xB0 is not a valid ASCII code. You can read here:

Any byte greater than hexadecimal 0x7F is decoded as the Unicode question mark ("?")

like image 181
Fratyx Avatar answered Dec 26 '22 02:12

Fratyx