首页 > 编程语言 > 详细

java无符号Byte

时间:2019-04-16 12:18:14      阅读:110      评论:0      收藏:0      [点我收藏+]

1.无符号byte, 实现了将byte(-128~127) 转换为 (0~255)

class UnsignedByte {
    private short value;
    private byte rawValue;

    private UnsignedByte() {
    }

    public static UnsignedByte toUnsignedByte(byte b) {
        UnsignedByte ub = new UnsignedByte();
        ub.rawValue = b;
        ub.value = (short) ((short) b & 0xFF);

        return ub;
    }

    public static byte toByte(UnsignedByte b) {
        return b.rawValue;
    }

    public static byte toByte(short i) {
        return (byte)i;
    }
}

 

java无符号Byte

原文:https://www.cnblogs.com/zhshlimi/p/10715928.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!