这是
Long number = 0x001122334455667788L;
我需要创建 Long 的最后 6 个字节的 byte[]
。
所以它看起来像
byte[] bytes = {0x22,0x33,0x44,0x55,0x66,0x77,0x88};
制作这样的东西的正确方法是什么?
感谢您的回复
最佳答案
byte[] buffer = new byte[6];
buffer[0] = (byte)(v >>> 40);
buffer[1] = (byte)(v >>> 32);
buffer[2] = (byte)(v >>> 24);
buffer[3] = (byte)(v >>> 16);
buffer[4] = (byte)(v >>> 8);
buffer[5] = (byte)(v >>> 0);
这就是DataOutputStream.writeLong()
的作用(除了它写入所有字节,当然)
关于java - 从 long 类型获取字节的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20361775/