A brief talk on different writing _java of Java byte array

Source: Internet
Author: User

(due to the length of the reasons for the lack of detailed science, do not like to spray).

Often see different definitions of byte arrays in Java, roughly sorted:

A byte (byte) = 8 bit (bit), "byte array" is All "byte", that is, each byte can be represented in binary, 16, decimal.

Binary: 00010110----->0*2^8 + 0*2^7 + 0*2^6 + 1*2^5 + 0*2^4 + 1*2^3 + 1*2^2 + 0*2^1 + 0*2^0 = 22
16 in: 0x16------->1*16^1 + 6*16^0 = 22

Decimal: 22

So the following three are equivalent:

byte [] aa = {00010110, 01010010, 10111000};
byte [] aa = {0x16, 0x52, 0xb8};

byte [] aa = {22, 82, 184};

When the Eclipse breakpoint is debugged, the contents of the byte array you see are expressed in decimal notation. Sometimes you see negative numbers, because more than 127 of the bytes in the byte array are displayed as negative numbers.

We know that the way Java reads only supports byte arrays, and byte is 8 bits, so it cannot exceed 127, and if it overflows, it is displayed as a negative number.

The above article on the Java byte array of different writing is small to share all the content of the whole, hope to give you a reference, but also hope that we support the cloud habitat community.

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.