mysql-protocol icon indicating copy to clipboard operation
mysql-protocol copied to clipboard

BufferUtil相关类疑惑

Open copyshop opened this issue 7 years ago • 2 comments

public static final void writeLong(ByteBuffer buffer, long l) { buffer.put((byte) (l & 0xff)); buffer.put((byte) (l >>> 8)); buffer.put((byte) (l >>> 16)); buffer.put((byte) (l >>> 24)); buffer.put((byte) (l >>> 32)); buffer.put((byte) (l >>> 40)); buffer.put((byte) (l >>> 48)); buffer.put((byte) (l >>> 56)); } 举这个方法的列子,为什么使用这些移位操作,比较疑惑。为什么是8 16 24 32 40 48 56,谢谢。

copyshop avatar Nov 26 '17 03:11 copyshop

你好,这些操作就是为了拿long类型没8个字节的值的,long是64位。

sea-boat avatar Dec 08 '17 00:12 sea-boat

谢谢。

copyshop avatar Dec 08 '17 02:12 copyshop