byte char short long float double理解

首先byte、short、int、long都是整数类型。

     ①:byte占一个字节,也就是8位,而且byte 是有符号整形 用二进制表示时候最高位为符号位 0代表正数 1代表负数。

max:01111111(十进制:2^8-1=127)    

min:是11111111吗?答案不是的。8位总共能表示256个数。00000000表示0,那10000000表示?

要注意正数在计算机中是以原码形式存在的,负数在计算机中是以其补码形式存在的,那么一个负数的补码是怎么计算的呢? 就是负数的绝对值的原码转为二进制再按位取反后加1。

-128的绝对值128,128源码10000000 取反:01111111 加1:10000000 故-128计算机中的表示就是 1000 0000 了。

-2^7(-128)<byte<2^7-1(127)

jdk中 Byte.class中的源代码:

 /**
     * A constant holding the minimum value a <code>byte</code> can
     * have, -2<sup>7</sup>.
     */
    public static final byte   MIN_VALUE = -128;
    /**
     * A constant holding the maximum value a <code>byte</code> can
     * have, 2<sup>7</sup>-1.
     */
    public static final byte   MAX_VALUE = 127;
     ②同理:short占2位,int占4位,long占8位,都是有符号整型。
 /**
     * A constant holding the minimum value a <code>short</code> can
     * have, -2<sup>15</sup>.
     */
    public static final short   MIN_VALUE = -32768;


    /**
     * A constant holding the maximum value a <code>short</code> can
     * have, 2<sup>15</sup>-1.
     */
    public static final short   MAX_VALUE = 32767;
                                     -2^15(-32768)<byte<2^15-1(32767)
/**
     * A constant holding the minimum value an <code>int</code> can
     * have, -2<sup>31</sup>.
     */
    public static final int   MIN_VALUE = 0x80000000;


    /**
     * A constant holding the maximum value an <code>int</code> can
     * have, 2<sup>31</sup>-1.
     */
    public static final int   MAX_VALUE = 0x7fffffff;

                            -2^31(-2147483648)<byte<2^31-1(2147483647)
 /**
     * A constant holding the minimum value a <code>long</code> can
     * have, -2<sup>63</sup>.
     */
    public static final long MIN_VALUE = 0x8000000000000000L;


    /**
     * A constant holding the maximum value a <code>long</code> can
     * have, 2<sup>63</sup>-1.
     */
    public static final long MAX_VALUE = 0x7fffffffffffffffL;

                                       -2^63<byte<2^63-1
char作为16位无符号整形 其范围为 0 —— 2^15,float占4位,double占8位。

谢谢这位大哥:转载地址
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值