Non-Signed Conversion of the number of javacard Environments

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.