Skip to content

Instantly share code, notes, and snippets.

@HyCraftHD
Created December 11, 2019 16:17
Show Gist options
  • Save HyCraftHD/5295edf93dec43c6fd51ab3d77b47806 to your computer and use it in GitHub Desktop.
Save HyCraftHD/5295edf93dec43c6fd51ab3d77b47806 to your computer and use it in GitHub Desktop.
Endian converter java
public static void endianConverter(byte[] buffer, int length) {
if (buffer.length % length != 0 || length % 2 != 0) {
throw new IllegalStateException();
}
for (int index = 0; index < buffer.length; index += length) {
for (int endianIndex = 0; endianIndex < length / 2; endianIndex++) {
final byte temp = buffer[index + endianIndex];
buffer[index + endianIndex] = buffer[index + length - endianIndex - 1];
buffer[index + length - endianIndex - 1] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment