Short data_length = (short) (apdu_buffer [iso7816.offset _ LC] & 0xff );
JavaProgramming LanguageThe integer data in is signed, that is, the highest bit determines whether it is a positive number or a negative number. However
The LC domain should be interpreted as an unsigned value because it has a negative length and is meaningless. AboveCodeSection,
LC bytes are in the phase of BITs and constant 0xff to convert signed bytes into unsigned values.
Another aspect
In the javacard environment, the number range expansion rules are as follows:
Assume that the following two variables are defined:
Byte;
Short B;
When a is less than 0x80, it ranges from 0x0 --- 0 x 7f to 0---127.
Perform the following operations:
B = (short);
In this case, the values of Lower 8 bits and lower a bits and higher 8 bits are all 0;
However, when a = 0x80 or above
Perform the following operations:
B = (short);
At this time, the lower 8 bits of B are still equal to the, but the higher 8 bits are all 1
All of this is because all the numbers in the javacard environment are signed. Number range expansion MEETING
Judge the status of a high position. When the value is 0, all the extended 8-bit values are 0;
When the value is 1, the extended 8-digit height is also 1;
Therefore, when expanding the range of the number of rows, you need to add
& Operation, as follows:
B = (short) (A & 0xff );
After this operation, the height of B is always 0. The number is non-signed.