1. 程式人生 > >java Byte原始碼分析

java Byte原始碼分析

原始碼:

1 public static int toUnsignedInt(byte x) {
2         return ((int) x) & 0xff;
3     }

原理:

-128(byte) 原碼:10000000 反碼:11111111 補碼:10000000
-128(byte)轉換為int型別: 10000000 -> 11111111 11111111 11111111 10000000 -128(int)& 0xff : 11111111 11111111 11111111 10000000 & 11111111 = 00000000 00000000 00000000 10000000