0

Hi I just encountered with one question of conversion from byte to int. code was like this

byte b=(byte)-1;
System.out.println(b);
char c=(char) b;

System.out.println(c);
int i=c;
System.out.println(i);

what I understood is when we convert int -1 to byte it will make 8 bit 2's compliment of +1 so value will be like 1111 1111. when we convert that into char based on MSB it will append 1 or 0. and from char to int just widening conversion is there. but I got output like this.

-1
?
65535

I didn't get why it is printing "?" in 2nd place. please help me out on this

LowCool
  • 1,187
  • 5
  • 25
  • 51
  • http://stackoverflow.com/a/25709790 – Grexis Nov 03 '16 at 05:59
  • 2
    If you print a `char`, it's being shown as a character - if possible. However Unicode codepoint 65535 (0xFFFF) is not a character, so it prints a question mark to indicate that instead - https://en.wikipedia.org/wiki/Specials_(Unicode_block) – Erwin Bolwidt Nov 03 '16 at 06:03
  • OK thanks one question if OS is 32 bit will output will be affected? – LowCool Nov 03 '16 at 06:58

0 Answers0