Necessity of 0XFF use 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 the 32-bit computer, the numbers are stored in 32 format, if it is a byte (8-bit) type of number, his high 24-bit inside are random numbers, low 8-bit

is the actual data. The parameter of the Java.lang.Integer.toHexString () method is an int (32-bit) type, and if you enter a byte (8-bit) type of number, the

The method will also consider the height of the number 24 as a valid bit, which will inevitably lead to errors, using & 0XFF operation, can be high 24 position 0 to avoid such errors

The occurrence

0xFF = 1111 1111 Low 8 bit is 1, high is 0

Therefore, the &0XFF can be set to the high position of the number is 0, low 8-bit unchanged

http://blog.csdn.net/guo_rui22/article/details/2826308

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

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.