public class ByteConversions extends Object
Modifier and Type | Method and Description |
---|---|
static int[] |
byteArrayToIntArray(byte[] src)
Converts a byte array to an int array.
|
static void |
byteArrayToIntArray(int[] out,
byte[] src)
Converts a byte array to an int array.
|
static int |
bytesToInt(byte[] bytes)
Converts a byte array into an integer value.
|
static long |
bytesToLong(byte[] src,
int offset,
int length)
Converts bytes to a long value.
|
static byte[] |
concatByteArrays(byte[]... bytes) |
static byte[] |
flattenByteArrays(byte[][] arr) |
static byte[] |
getBytesFromLong(long in) |
static int[] |
getIntArrayFromBytes(byte[] bytes,
int lengthOfIntInBits)
Fetches integers from the provided byte array.
|
static int[] |
getIntArrayFromBytes(byte[] bytes,
int lengthOfIntInBits,
boolean littleEndian)
Fetches integers from the provided byte array.
|
static long |
getLongFromBytes(byte[] b) |
static byte[] |
intArrayToByteArray(int[] src)
Converts an integer array to a byte array.
|
static void |
intToBytes(byte[] dest,
int offset,
int value)
Converts an int value to bytes.
|
static byte[] |
intToBytesLittleEndian(int src)
Converts an int value in big endian representation to bytes in little endian representation.
|
static int |
littleToBigEndian(int input)
Converts an int value in big endian to little endian representation.
|
static void |
longToBytes(byte[] dest,
int offset,
int length,
long value)
Converts a long value to bytes.
|
static byte[] |
shortArrayToByteArray(int[] src)
Converts a short array to a byte array.
|
public static int[] getIntArrayFromBytes(byte[] bytes, int lengthOfIntInBits)
bytes
- the source byte arraylengthOfIntInBits
- the length of the integers in bitInvalidParameterException
- if the length of bytes does not math with the
requested bit lengthpublic static int[] getIntArrayFromBytes(byte[] bytes, int lengthOfIntInBits, boolean littleEndian)
bytes
- the source byte arraylengthOfIntInBits
- the length of the integers in bitlittleEndian
- iff true, then the algorithm interprets the byte array
as little endian. Big endian otherwise.InvalidParameterException
- if the length of bytes does not math with the
requested bit lengthpublic static byte[] getBytesFromLong(long in)
public static long getLongFromBytes(byte[] b)
public static byte[] flattenByteArrays(byte[][] arr)
public static byte[] concatByteArrays(byte[]... bytes)
public static void longToBytes(byte[] dest, int offset, int length, long value)
dest
- byte arrayoffset
- offsetlength
- lengthvalue
- long valuepublic static void intToBytes(byte[] dest, int offset, int value)
dest
- byte arrayoffset
- offsetvalue
- long valuepublic static byte[] intToBytesLittleEndian(int src)
src
- input
returns bytes in little endian representationpublic static int littleToBigEndian(int input)
input
- input integer in big endian representation
returns integer in little endian representationpublic static int bytesToInt(byte[] bytes)
bytes
- input byte arraypublic static long bytesToLong(byte[] src, int offset, int length)
src
- byte arrayoffset
- offsetlength
- lengthpublic static byte[] intArrayToByteArray(int[] src)
src
- byte arraypublic static byte[] shortArrayToByteArray(int[] src)
src
- byte arraypublic static int[] byteArrayToIntArray(byte[] src)
src
- byte arraypublic static void byteArrayToIntArray(int[] out, byte[] src)
out
- destination array where the integer values will be written tosrc
- source byte arrayCopyright © 2020–2025 Stiftung SIC. All rights reserved.