java设计byte类型为1个字节,1个字节占8位,即8bit,这是常识。java
另外,计算机系统中是用补码来存储的,首位为0表示正数,首位为1表示负数,因此有如下结论:面试
最大的补码用二进制表示为:01111111= 127后端
最小的补码用二进制表示为:10000000= -128多线程
关于补码、原码、反码的计算原理能够百度。架构
Byte的源码:工具
/*** A constant holding the minimum value a {@code byte} can线程
* have, -27.设计
*/code
public static final byte MIN_VALUE = -128;教程
/**
* A constant holding the maximum value a {@code byte} can
* have, 27-1.
*/
public static final byte MAX_VALUE = 127;
7是最高位,总共8bit,能够看出byte占1个字节,即8/8=1。
Integer源码:
/*** A constant holding the minimum value an {@code int} can
* have, -231.
*/
public static final int MIN_VALUE = 0x80000000;
/**
* A constant holding the maximum value an {@code int} can
* have, 231-1.
*/
public static final int MAX_VALUE = 0x7fffffff;
31是最高位,总共32bit,能够看出int占4个字节,即32/8=4。
其余Short、Long的设计原理也同样。
推荐去个人博客阅读更多:
2.Spring MVC、Spring Boot、Spring Cloud 系列教程
3.Maven、Git、Eclipse、Intellij IDEA 系列工具教程
生活很美好,明天见~