i2b 0x91
Converts the int on top of the stack to byte.
- Opcode
0x91(145)- 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 byte, leaving it on the stack as an int.
Narrows an int to byte by keeping its low 8 bits and sign-extending back to int. javac emits it for casts like (byte) i and for compound assignments to byte variables, such as b += 1, which compute in int.
How often javac uses it
In JDK 25.0.5's java.base module, i2b appears 2,036 times in 280 of its 7,391 classes: 0.10% of all instructions, the 89th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedOutputStream.write, java.io.ByteArrayOutputStream.write, java.io.DataInputStream.readByte, java.io.DataOutputStream.writeBytes.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; i2b is highlighted.
static double convert(int i, long l, float f, double d) in Tour, compiled by javac 25Related 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, i2b (Java SE 25).