Necessity of using 0XFF in java. lang. Integer. toHexString (B [n] & 0XFF)

Source: Internet
Author: User

Byte [] B = {1, 2, 20,108 };

String stmp = java. Lang. Integer. tohexstring (B [N] & 0xff)

 

In 32-bit computers, numbers are stored in 32 format. If a byte (8-bit) number is used, its 24-bit height is a random number, which is 8-bit lower.

Is the actual data. The parameter of Java. Lang. Integer. tohexstring () method is of the INT (32-bit) type. If you enter a byte (8-bit) type number

The method regards the value 24 as a valid bit, which will inevitably lead to errors. Using the & 0xff operation, you can set the value 24 to 0 to avoid such errors.

.

Related Article

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.