(Due to the length reason, the explanation is not detailed and scientific enough, please do not criticize if you don’t like it).
I often see different definitions of byte arrays in Java, so I will sort them out:
One byte = 8 bits, and all "byte array" is "byte", that is, each byte can be represented in binary, hexadecimal, and 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
Hexadecimal: 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 debugging Eclipse breakpoints, the contents of the byte arrays you see are expressed in decimal. Sometimes you see negative numbers because numbers over 127 in the byte array will be displayed as negative numbers.
We know that Java reads only support byte arrays, while byte is 8 bits, so it cannot exceed 127. If it exceeds, it will overflow and be displayed in the form of a negative number.
The above article briefly talks about the different writing methods of Java's byte array is all the content I share with you. I hope you can give you a reference and I hope you can support me more.