Integers#
byte#
1 byte, 8 bits
Maximum value: 0111_1111
corresponds to decimal 127
Minimum value: 1111_1111
, but computers use two's complement
, so the minimum value should be represented in two's complement
, which is 1000_0000
in binary and corresponds to -128
Therefore, the range of byte type is -128
to 127
For more information about sign-magnitude, one's complement, and two's complement, refer to: Sign-Magnitude, One's Complement, and Two's Complement
short#
2 bytes, 16 bits, range: [-2^15, 2^15-1]
int#
4 bytes, 32 bits, range: [-2^31, 2^31-1]
long#
8 bytes, 64 bits, range: [-2^63, 2^63-1]
Floating Point Numbers#
Floating point numbers consist of three parts:
- Sign bit (1 bit)
- Exponent (8 bits for float, 11 bits for double)
- Mantissa (23 bits for float, 52 bits for double)