System.out.println((byte) (1.0/0));
System.out.println((short) (1.0/0));
System.out.println((int) (1.0/0));
System.out.println((long) (1.0/0));
The result is:
-1
-1
2147483647
9223372036854775807
In binary format:
1111 1111
1111 1111 1111 1111
0111 1111 1111 1111 1111 1111 1111 1111
0111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1111
Why casting infinity to int and long integers keeps sign bit as "0", while sets sign bit to "1" for byte and short integers?