java無符號Byte


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;
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM