Search code examples
javaoperatorsbit-manipulationbitwise-operatorstypecast-operator

Java : Operators and Typecasting


long value = 0x88888888 ;
int i = (int) (value & 0xff);

How does the above evaluation of expression take place? Is it

int i = (int)value & (int)0xff ;

or does the bitwise and operation gets evaluated first? I am getting confused :-|


Solution

  • First the bitwise operation is evaluated as an operation on longs (the parenthesis guarantee it). Then the result is cast to int.