One, Notes
1. Large capacity can not be directly assigned to a small volume; large capacity needs to be converted to a small capacity, cast, cast need to add "cast character" plus operator then cast by the compiler but with reduced accuracy there are likely to lose. So cast to be used with caution. After the loss of accuracy due to the potential loss is very serious.
example:
The underlying principle: long is eight bytes, now converted to a four-byte int type, then the first four bytes to be deleted
long i5 = 100L; //int i6 = i5; int i6 = (int)i5; System.out.println(i6);
2. Special examples 1
Raw Data: 00000000 00000000 00000000 00000000 00000000 00000000 1,000,000,000,000,000
We cast to int is four bytes :( deleted the first four bytes)
10000000 00000000 00000000 00000000
long i7 = 2147483648L; int i8 = (int)i7; System.out.println(i8);
Internal storage the data is stored in the form of a computer by the underlying principles of complement, the digital change.
3. Specific examples 2
byte i11 = 50; byte i9 = 127; byte i10 = 128;
(1) Logically speaking literal numbers, then give this default Java literals four bytes, but we see the first line, we give 50 as a byte but can compile, because the java language, when a literal integer type does not exceed the byte value range, the literal can be assigned directly to a variable of type byte, you see the third row, he is out of range. So that is an error.
4. calculated original code, complement: Self Baidu
Second, the source code:
d13_int_type_specific_example.java
Address: https: //github.com/ruigege66/Java/blob/master/d13_int_type_specific_example.java
2.CSDN: https: //blog.csdn.net/weixin_44630050 (Xi Jun Jun Moods do not know - Rui)
3. Park blog: https: //www.cnblogs.com/ruigege0000/
4. Welcomes the focus on micro-channel public number: Fourier transform, backstage reply "gifts" to get big data learning materials