java 中字节数组的循环位移位

circular bit shifting in byte array in java

对于16字节的数组,如何左移一个字节(8位移位)?

即16 字节数组:(0x) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

左移8位后:

输出应为:(0x) 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00

如何在 java 中执行此操作?

这是一种(不是很优雅)的方式:

byte[] bytes = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe};

// now shift left
byte b0 = bytes[0];
System.arraycopy(bytes, 1, bytes, 0, bytes.length -1);
bytes[bytes.length - 1] = b0;