One: Java data type conversion In addition to Boolean type Boolean (cannot convert) there are two kinds of:< > Automatic conversion; < two > casting
< >, automatic Conversion: The small data type is automatically converted to a large data type. for example, when int and byte are computed, byte ( -128~127) is automatically converted to the type of int ( -2147483648~2147483647).
0.1. Automatic conversion of basic data types:byte->short,char, int, Long Floatdouble, Long
Remember:
Small Turn big, big turn little will lose precision!!!
<1> Conversion of byte:
byte a=120;
byte b=a+80; Tip: types converted to byte from int type (80) may lose precision
System.out.println (b);
<2> Char character conversion
Char id= ' a '; a=97
int i=ID+3;
System.out.println (i); -
<3> Remember that once the int:int reaches its maximum value, it does not raise its type, but directly loses Precision.
int id=2147483647;
int g=id+1;
System.out.println (g); -2147483648
Why would it be negative -2147483648?
the reason is:2147483647 binary is: 0111 1111 1111 1111 1111 1111 1111 1111
if after +1 its binary is: 1000 0000 0000 0000 0000 0000 0000 0000 After conversion to decimal:-2147483648
Conversion of data types in Java