- BYTE, short, int, long:
- BYTE takes 8 bits (bit) binary: 0000 0000 and 1111 1111, decimal: -128 < byte < 127
- Short takes 2 bytes (byte), 16 bits (bit)
- int is 4 bytes (byte), 32 bit (bit)
- Long takes 8 bytes, 64 bits (bit)
- float, double
- Float takes 4 bytes, 32 bits
- Double takes 8 bytes, 64 bits
- Char
- Char takes 2 bytes, 16 bits
- Boolean
- Boolean accounted for 1/8 bytes, 1 bits
calculation table for binary calculator1000 0000 = 1280100 0000 = 640010 0000 = 320001 0000 = 160000 1000 = 80000 0100 = 40000 0010 = 20000 0001 = 10000 0000 = 0
Binary speed algorithm:
Ideas:
- 195 is greater than 128 so the highest position is 1:1XXX XXXX
- 195-128 = 67 is greater than 64 so the highest second bit is calculated as 1:11XX XXXX
- 67-64 = 3 is greater than 2 so the projection is: 1100 001X
- 3-2 = 1 So the extrapolation is: 1100 0011 is the binary of 195
calculation between basic data types:
- The computed result between Byte, short, char is int
- int + Long = long
- int + float = float
- int + double = Double
- Any type that is added to string is string
Detailed Java basic data types