简体   繁体   中英

Why aren't these two byte operations equal?

I have the following code:

ByteBuffer bb = ByteBuffer.allocate(totalLength);
bb.putShort(3);
bb.putShort(0);

bb.putInt(3 << 15 + 0);

I don't understand why putting the two short values into the byte buffer isn't the same as the second operation

Try bb.putInt(3 << 16 + 0) instead:)

You could also inspect your ByteBuffer with:

System.out.println(Arrays.toString(bb.array()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM