i2c 0x92

Converts the int on top of the stack to char.

Opcode
0x92 (146)
Family
Conversions
Operands
none
Length
1 byte
Operand stack
…, value (int) → …, result (int)
Can throw
nothing at run time (beyond linking errors)

What it does

Converts the int on top of the stack to char, leaving it on the stack as an int.

Narrows an int to char by keeping its low 16 bits and zero-extending back to int. javac emits it for casts like (char) i and for compound assignments to char variables, such as c += 1, which compute in int.

How often javac uses it

In JDK 25.0.5's java.base module, i2c appears 443 times in 123 of its 7,391 classes: 0.02% of all instructions, the 126th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedWriter.write, java.io.CharArrayWriter.write, java.io.DataInputStream.readLine, java.io.ObjectInputStream$BlockDataInputStream.readUTFSpan.

Example

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; i2c is highlighted.

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
38byte b = (byte) i;
0iload_0 // i
1i2b
2istore 6// b
39char c = (char) i;
4iload_0 // i
5i2c
6istore 7// c
40short s = (short) i;
8iload_0 // i
9i2s
10istore 8// s
41long il = i;
12iload_0 // i
13i2l
… 73 instructions after

Open in the viewer

Related instructions

i2l Converts the int on top of the stack to long.i2f Converts the int on top of the stack to float.i2d Converts the int on top of the stack to double.

Specification: JVMS §6.5, i2c (Java SE 25).