Java语言基本数据类型大小
2018-10-22 本文已影响0人
YNZXGWZM
| 类型 | 字节数 | 位数 | 取值范围 |
|---|---|---|---|
| Byte | 1 | 8 | -128~127 |
| char | 2 | 16 | -2的15次方到2的15次方-1 |
| shout | 2 | 16 | -2的15次方到2的15次方-1 |
| int | 4 | 32 | -2的31次方到2的31次方-1 |
| long | 8 | 64 | -2的63次方到2的63次方-1 |
| Float | 4 | 32 | 3.402823e+38 ~ 1.401298e-45 |
| double | 8 | 64 | 1.797693e+308~ 4.9000000e-324 |
| boolean | 1(前7位是0) | 1 | 0~1 |
public static void main(String[] args) throws UnsupportedEncodingException {
//负数的2进制计算方法是,除了符号位之外,取反再加1。
// 所以1000 0000 ,除符号位之后,取反得到 111 1111 ,再加1得到:1000 0000 = -128 符号位要记得。
//而1111 1111 ------取反-----> 1000 0000 --------加1---------> 1000 0001 = -1这边符号位还在。
int length = new String("付").getBytes("GBK").length;
System.out.println(Byte.MAX_VALUE); //127 1111 1111 去掉符号位 111 1111 =2的7次方减1 =2^7-1
System.out.println(Byte.MIN_VALUE); //-128
System.out.println(Short.MAX_VALUE); //32767
System.out.println(Short.MIN_VALUE); //-32768
System.out.println(Integer.MAX_VALUE);//2147483647
System.out.println(Integer.MIN_VALUE); //-2147483648
System.out.println(Long.MAX_VALUE); //9223372036854775807
System.out.println(Long.MIN_VALUE); //-9223372036854775808 总共19long类型的数字
}