If I convert a character to byte
and then back to char
, that character mysteriously disappears and becomes something else. How is this possible?
This is the code:
char a = 'È'; // line 1
byte b = (byte)a; // line 2
char c = (char)b; // line 3
System.out.println((char)c + " " + (int)c);
Until line 2 everything is fine:
In line 1 I could print "a" in the console and it would show "È".
In line 2 I could print "b" in the console and it would show -56, that is 200 because byte is signed. And 200 is "È". So it's still fine.
But what's wrong in line 3? "c" becomes something else and the program prints ? 65480
. That's something completely different.
What I should write in line 3 in order to get the correct result?