Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Detailed description of integer data
Detailed description of integer data
Like C and C++, there are three forms of integer constants in Java:

(1) decimal integer, such as 123, -456, 0.

(2) Octal integer, starting from 0, such as 0 123 for decimal number 83, -0 1 1 for decimal number -9.

(3) Hexadecimal integer, starting with 0X or 0x, such as 0x 123 for decimal number 29 1 and 0x 12 for decimal number-18.

Integer constants occupy 32 bits in the machine and take the value of int. For long values, add l or l after the number. For example, 123L stands for long integer, accounting for 64 bits in the machine. There are four types of integer variables: byte, short, int and long. The following table lists the number of bits stored in each type and their ranges.

Int class is the most commonly used integer class. The data range it displays is large enough for 32-bit and 64-bit processors. But for large-scale calculation, we often encounter a large integer, which is beyond the range shown by int type, so we should use long type.

Because different machines have different storage formulas for multi-word data, data can be stored from low byte point to high byte point or from high byte point to low byte point. In this way, when analyzing network negotiation or document format, in order to solve the storage order problem of multi-byte points on different machines, it is appropriate to represent data in byte form. However, in general, because the data displayed in it is small and easy to overflow, it should be avoided.

Short type is rarely used, and it limits the storage of data to high bytes first and then low bytes, which will make mistakes on some machines. For example:

Byte b; //Specify variable b as byte type.

Short s; //Specifies that the variable s is of short type.

int I; //Specifies that the type of variable I is int.

Long l; //Specifies that the type of variable l is long.