SunnyX
asked on
Core Java. What output will be and why ?
int x = (int) (char) (byte) -1;
System.out.println(x);
Could you explain step by step what happen here and why ? thanks you in advance !
byte in Java is signed 8-bit twos' complement - so the -1 as a byte is eight 1s , ie. 11111111.
the char and int casts are meaningless, so you end up with an int (which in Java is 32-bit signed two's complement, giving the positive decimal result of 65535.
Is that what you meant to ask?
the char and int casts are meaningless, so you end up with an int (which in Java is 32-bit signed two's complement, giving the positive decimal result of 65535.
Is that what you meant to ask?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(char)
quite right - I overlooked the char cast as material like that.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx everybody !
-1 --> Byte (1) --> Char (Some Weird Character) -- > Int --- > 65535.
-1 --> Byte -- > -1
-1 --> Char --> 'ï¿¿'
'ï¿¿' --> Int - > 65535