1. Table comparison:
2. Convert into binary:
Java in byte to represent the binary, because byte has 8 bits, and int has 32 bits, so the int to binary should be removed from the high save the lowest 8 bits, the following code:
public static byte[] Inttobytes (int value)
{
byte[] src = new byte[4];
SRC[3] = (Byte) ((value>>24) & 0xFF);
SRC[2] = (Byte) ((value>>16) & 0xFF);
SRC[1] = (Byte) ((value>>8) & 0xFF);
Src[0] = (Byte) (value & 0xFF);
for (byte b:src) {
System.out.println (b);
}
return src;
}
int is 4 bytes, so converting to byte is definitely a byte array, and several other types can refer to int, specifically
3.java shift Operation:
Left displacement low complement, there is displacement high complement, such as: right displacement 500>>24 meaning is left to fill 24 0, and then from left to right 32 digits is the result; left offset 0, right to left
This is for the unsigned, the symbol is temporarily unclear, to be mended ...
4. Binary and Byte:
The range of byte is -128--127, the highest bit 0 indicates positive, 1 is negative, so it is 2^7-1
Concept: Java in the complement to the binary number, the highest bit of the complement is the symbol bit, the highest bit of "0" for positive numbers, the highest bit of "1" for negative numbers.
The positive complement is its own;
Negative complement for its absolute value you take 1;
For example:
+21, the binary representation is 00010101, then its complement is also 00010101
-21, according to the concept of its absolute value of 00010101, you take the inverse of 11101010, plus 1 to 11101011, that is, 21 of the binary representation is 11101011
Steps:
1, byte is a byte 8 bits, the highest bit is the sign bit, that is, the maximum value is 01111111, because the complement of a positive number is itself, that is, this positive number is 01111111
Decimal representation is 127
2, the maximum positive number is 01111111, then the minimum negative is 10000000 (the largest negative number is 11111111, i.e.-1)
3, 10000000 is the minimum negative number of the complement representation, we have the complement calculation step upside down. 10000000 minus 1, 01111111, then reverse 10000000.
Because the complement of a negative number is its absolute value, that is, 10000000 is the absolute value of the smallest negative number, and 10000000 decimal is 128, so the minimum negative number is-128
4, from this can be derived from the range of byte is-128 to +127
5, note: Each type of value range of the calculation method and this is roughly the same, interested students can try to calculate their own
Supplement (to the students who are not computer majors to sweep the blind):
In the computer, fixed-point number has 3 kinds of representations: the original code, the inverse code and the complement
[The original code] is the binary fixed-point notation, that is, the highest bit is the sign bit, "0" means positive, "1" means negative, and the remaining bits represent the size of the value.
The [anti-code] notation stipulates that the inverse code of a positive number is the same as its original code; the inverse of a negative number is a bitwise counter to its original code, except for the sign bit.
The [complement] notation stipulates that the complement of a positive number is the same as its original code; the complement of a negative number is at the bottom of its inverse code plus 1.
So System.out.println ((byte) 170); The result is-86
The 170 binary is 10101010, the counter is 1010101, the decimal is 85, then the 1, because the highest digit is 1, so the result is-86.