Why is the byte b = 0x80; report type incompatible while byte b = 0x70 has no error message?

question 0:

//java
//
byte b = 0x80;
// 
byte b = 0x70;

question 1:
0x80 We use the usual binary (no complement) to express that it should be 1000 0000. is the 1 in the binary a symbol bit (because I guess the above problem may be related to the symbol bit). )?
question 2:
if byte b =-10; does the system first check the positivity and negativity of-10 and then calculate the complement and store it on the computer? Or the phrase "the complement of a positive number is itself, and the complement of a negative number is an inverse + 1" is only a regular summary, so it cannot be understood in this way?
question 3:
how to explain-2 and 4294967294 are actually 0xFFFFFFFE stored in memory classes

Mar.10,2021

the range of data that byte can store is-128. 0x80 is out of this range, so it is not compatible.

  1. No. 0x80 is an integer of type int , corresponding to 128 , not a negative number. The literal quantity of a number is a int type unless it is followed by l or L to indicate that it is a long type.
  2. When byte b =-10; , the system considers -10 to be a int , and this int is just within the range of-128 code 127, so initialize b of byte type to -10 . Otherwise, an exception is thrown.
  3. if there is 0xFFFFFFFE in memory, then he can only represent -2 and 4294967294 . It can represent one or several characters, an audio clip, a picture clip, a dot,. Wait. As for what it means, it lies in the procedure. If it represents a variable, its exact value depends on the definition of the variable type.

if you see through the memory bar that the value of a space is 10101000001010001010101, no one knows what it means. What it is willing to do is the program, it is the code.


question 1: if 0x80 can be expressed as 1000 000, it means that this representation is an unsigned binary representation, does not involve symbol bits, and 1 is not a symbol bit.

question 2: complements are defined, not regular summaries. byte b =-10 this code must be parsed and compiled, and then the data is stored, so first checks the positivity and negativity of-10 and then calculates the complement .

question 3: there is 0xFFFFFFFFFE in a piece of memory, which can actually be interpreted as any meaning. The key is to see which rules the program interprets. If you think of it as an unsigned integer, it is 4294967294, and if you think of it as a complement, it is-2.

Menu