Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BufferUtil相关类疑惑 #3

Open
copyshop opened this issue Nov 26, 2017 · 2 comments
Open

BufferUtil相关类疑惑 #3

copyshop opened this issue Nov 26, 2017 · 2 comments

Comments

@copyshop
Copy link

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,谢谢。

@sea-boat
Copy link
Owner

sea-boat commented Dec 8, 2017

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

@copyshop
Copy link
Author

copyshop commented Dec 8, 2017

谢谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants