i2s

Convert int to short

Bytecode

Type Description
u1 i2s opcode = 0x93 (147)

Stack ..., value => ..., result

Description

Converts an integer to a signed short.

The value on the top of the operand stack must be of type int. It is popped from the operand stack, truncated to a short, then sign-extended to an int result. The result is pushed onto the operand stack.

i2s is used in Java where there is an explicit case between an int and a short. Notice that i2s can cause a change in sign. For example, in the code:

    int x = -40000;
    short s = (short)x;

The value of s is positive 25536, since the sign bit of x is lost in the conversion.

Notes

The i2s instruction performs a narrowing primitive conversion. It may lose information about the overall magnitude of value. The result may also not have the same sign as value.