i2c

Convert int to char

Bytecode

Type Description
u1 i2c opcode = 0x92 (146)

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

Description

Converts an integer to a 16-bit unsigned char.

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

i2c is used in Java when there is an explicit cast between an int and a char. Notice that i2c produces an unsigned value - any sign bit for the original number is lost. For example, in the code:
    int x = -1;
    char c = (char)x;

The value of c is positive 0xFFFF.

Notes

The i2c instruction performs a narrowing primitive conversion. It may lose information about the overall magnitude of value. The result (which is always positive) may also not have the same sign as value.