i2s 0x93

Converts the int on top of the stack to short.

Opcode
0x93 (147)
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 short, leaving it on the stack as an int.

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

How often javac uses it

In JDK 25.0.5's java.base module, i2s appears 229 times in 58 of its 7,391 classes: 0.01% of all instructions, the 142nd most common of 194 opcodes in use. Some of the methods that use it: java.io.ObjectOutputStream$BlockDataOutputStream.writeShort, java.io.RandomAccessFile.readShort, java.lang.Byte.shortValue, java.lang.Double.shortValue.

Example

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

static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25
… 2 instructions before
38byte b = (byte) i;
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
14lstore 9// il
42float lf = l;
16lload_1 // l
17l2f
… 70 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, i2s (Java SE 25).