Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个byte/ int 0001 0010(18)。我需要把这个byte/int分成
byte
int
0001 0010
18
0001 0000( 16) 和 0000 0010( 2)。
0001 0000
16
0000 0010
2
我怎样才能在 Java 中做到这一点?
&是按位与。-16是11110000二进制的,15是00001111.
&
-16
11110000
15
00001111
public static byte[] split(byte input) { byte[] output = new byte[2]; output[0] = (byte) (input & -16); output[1] = (byte) (input & 15); return output; }