added reverse byte order function

This commit is contained in:
Ziver Koc 2016-04-15 17:50:58 +02:00
parent 542b242c41
commit 0495d3289b
2 changed files with 23 additions and 0 deletions

View file

@ -95,6 +95,21 @@ public class ByteUtil {
return dest;
}
/**
* Creates a new byte array with reversed byte ordering
* (LittleEndian -> BigEndian, BigEndian -> LittleEndian)
*
* @param data is the byte array that will be reversed.
* @return a new byte array that will have the same data but in reverse byte order
*/
public static byte[] getReverseByteOrder(byte[] data){
byte[] dest = new byte[data.length];
if (data.length > 0)
for (int i=0; i<data.length; ++i)
dest[dest.length-1-i] = data[i];
return dest;
}
/**
* Returns a byte bitmask
*