Site Tools


Smart Card Solution

User Manual

JavaCard API Samples

Java Card Specification

Knowledge Sharing


7.5.98 srem

Remainder short




srem = 73 (0x49)


…, value1, value2 → …, result


Both value1 and value2 must be of type short. The values are popped from the operand stack. The short result is the value of the Java expression value1 - (value1 / value2) * value2. The result is pushed onto the operand stack.

The result of the irem instruction is such that (a/b)*b + (a%b) is equal to a. This identity holds even in the special case that the dividend is the negative short of largest possible magnitude for its type and the divisor is -1 (the remainder is 0). It follows from this rule that the result of the remainder operation can be negative only if the dividend is negative and can be positive only if the dividend is positive. Moreover, the magnitude of the result is always less than the magnitude of the divisor.

Runtime Exception

If the value of the divisor for a short remainder operator is 0, srem throws an ArithmeticException.

javacard/jcvm/7.5.98_srem.txt · Last modified: 2017/05/13 04:10 (external edit)