Search code examples
javaprimitive-typesnarrowing

What does this mean "Narrowing a primitive truncates the high order bits"


What does this mean "Narrowing a primitive truncates the high order bits"


Solution

  • E.g. if you cast long to int you are discarding the higher bits of the long.

    Short  -> Byte
    0x00FF -> 0xFF
    256    -> -128