Created
December 11, 2019 16:17
-
-
Save HyCraftHD/5295edf93dec43c6fd51ab3d77b47806 to your computer and use it in GitHub Desktop.
Endian converter java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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