Java long data type-materials learned online, long data type
Java long data type bit signedJavaRaw data type. When the calculation result of an integer may exceedintThe range of data types.
longThe data type range is-9,223,372,036,854,775,808To9,223,372,036,854,775,807(-2^63To2^63-1).
longAll integers in the Data Type range are calledlongType.longInteger constants of the type are always in uppercase.LOr lower caselEnd.
UselongExample of an integer literal:
long num1 = 0L; long num2 = 4L; long mum3 = -3; long num4 = 8; long num5 = -1L;
JavaLong literal
longThe literal value of the type can be expressed in octal, hexadecimal, and binary formats. For example,
long num1;num1 = 25L; // Decimal format num1 = 031L; // Octal formatnum1 = 0X19L; // Hexadecimal format num1 = 0b11001L; // Binary format
Java
WhenlongThe type of integer literal is assignedlongFor variable types, the Java compiler checks the value to be allocated and ensures that it is within the range of long data types; otherwise, a compilation error occurs.
Note:intTolongThe Type assignment is valid because it is stored inintAll values in the variable can be stored inlongType variable. However, it may not be becauselongType data RatiointThe type range is large. Therefore, you cannot simply storelongThe value in the variable is assignedintVariable. There is a possibility of value overflow.
TolongAssign the variable valueintVariable, please use "Conversion" in Java, as shown below:
num1 = (int)num2;
Java
Java hasLongClass, which defines two constants to represent long data typesLong.MAX_VALUEAndLong.MIN_VALUE.