Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - In Java, the int type is forced to the byte type. After the int type is forced to the byte type, how is it calculated that the data exceeds the representation range of the byte?
In Java, the int type is forced to the byte type. After the int type is forced to the byte type, how is it calculated that the data exceeds the representation range of the byte?

A byte is 8 bits, and an int is 16 bits. When converting int to byte, the first (left) 8 bits are discarded, leaving the last 8 bits.

88+68=156, converted to int type binary is 0000000010011100, and then converted to byte is 10011100. Because the highest bit is the sign bit, which is the bit that indicates positive and negative, so 1 here represents a negative number, and the rest is as follows The conversion of the original code and complement code rules is 100, so it is -100