java.lang.Object | |
↳ | com.pnfsoftware.jeb.util.io.EndianUtil |
Byte array to/from primitives with endianness support.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
EndianUtil() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static int | bigEndianBytesToInt(byte[] array) | ||||||||||
static int | bigEndianBytesToInt(byte[] array, int offset) | ||||||||||
static long | bigEndianBytesToLong(byte[] array, int offset) | ||||||||||
static long | bigEndianBytesToLong(byte[] array) | ||||||||||
static short | bigEndianBytesToShort(byte[] array) | ||||||||||
static short | bigEndianBytesToShort(byte[] array, int offset) | ||||||||||
static int |
bytesToInt(byte[] array, int offset, ByteOrder order)
Read 4 bytes and convert it to an integer.
| ||||||||||
static long |
bytesToLong(byte[] array, int offset, ByteOrder order)
Read 8 bytes and convert it to a long.
| ||||||||||
static long |
bytesToNumberSigned(ByteOrder bo, byte[] b)
Convert a byte array to a number, sign is extended to long, meaning that {0x88} will result
in 0xFFFFFFFF_FFFFFF88L
| ||||||||||
static long |
bytesToNumberUnsigned(ByteOrder bo, byte[] b)
Convert a byte array to a number, zero extended to long, meaning that {0x88} will result in
0x88L
| ||||||||||
static short |
bytesToShort(byte[] array, int offset, ByteOrder order)
Read 2 bytes and convert it to a short.
| ||||||||||
static byte[] |
intToBEBytes(int v)
Convert a 32-bit integer to a big-endian encoded array of bytes.
| ||||||||||
static void | intToBEBytes(int v, byte[] output, int offset) | ||||||||||
static void | intToBEBytes(int v, byte[] output) | ||||||||||
static void | intToLEBytes(int v, byte[] output, int offset) | ||||||||||
static byte[] |
intToLEBytes(int v)
Convert a 32-bit integer to a little-endian encoded array of bytes.
| ||||||||||
static void | intToLEBytes(int v, byte[] output) | ||||||||||
static int | littleEndianBytesToInt(byte[] array) | ||||||||||
static int | littleEndianBytesToInt(byte[] array, int offset) | ||||||||||
static long | littleEndianBytesToLong(byte[] array) | ||||||||||
static long | littleEndianBytesToLong(byte[] array, int offset) | ||||||||||
static short | littleEndianBytesToShort(byte[] array, int offset) | ||||||||||
static short | littleEndianBytesToShort(byte[] array) | ||||||||||
static byte[] |
longToBEBytes(long v)
Convert a 64-bit integer to a big-endian encoded array of bytes.
| ||||||||||
static void | longToBEBytes(long v, byte[] output) | ||||||||||
static void | longToBEBytes(long v, byte[] output, int offset) | ||||||||||
static void | longToLEBytes(long v, byte[] output) | ||||||||||
static byte[] |
longToLEBytes(long v)
Convert a 64-bit integer to a little-endian encoded array of bytes.
| ||||||||||
static void | longToLEBytes(long v, byte[] output, int offset) | ||||||||||
static void |
numberToBytes(ByteOrder bo, long v, byte[] output)
Automatically convert a value depending on the byte array size.
| ||||||||||
static void | shortToBEBytes(short v, byte[] output) | ||||||||||
static void | shortToBEBytes(short v, byte[] output, int offset) | ||||||||||
static byte[] |
shortToBEBytes(short v)
Convert a 16-bit integer to a big-endian encoded array of bytes.
| ||||||||||
static void | shortToLEBytes(short v, byte[] output) | ||||||||||
static byte[] |
shortToLEBytes(short v)
Convert a 16-bit integer to a little-endian encoded array of bytes.
| ||||||||||
static void | shortToLEBytes(short v, byte[] output, int offset) | ||||||||||
static void |
swap(byte[] array, int offset, int size)
Flip the byte order of an array of bytes.
| ||||||||||
static void |
swap(byte[] array)
Flip the byte order of an array of bytes.
| ||||||||||
static void |
swapByGroup(byte[] array, int grpByteCount)
Flip the byte order of groups of bytes.
| ||||||||||
static int |
swapInt(int v)
Swap the byte ordering of an int.
| ||||||||||
static long |
swapLong(long v)
Swap the byte ordering of a long.
| ||||||||||
static short |
swapShort(short v)
Swap the byte ordering of a short.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Read 4 bytes and convert it to an integer.
array | input buffer |
---|---|
offset | buffer offset |
order | endianness |
Read 8 bytes and convert it to a long.
array | input buffer |
---|---|
offset | buffer offset |
order | endianness |
Convert a byte array to a number, sign is extended to long, meaning that {0x88} will result in 0xFFFFFFFF_FFFFFF88L
Convert a byte array to a number, zero extended to long, meaning that {0x88} will result in 0x88L
Read 2 bytes and convert it to a short.
array | input buffer |
---|---|
offset | buffer offset |
order | endianness |
Convert a 32-bit integer to a big-endian encoded array of bytes.
Convert a 32-bit integer to a little-endian encoded array of bytes.
Convert a 64-bit integer to a big-endian encoded array of bytes.
Convert a 64-bit integer to a little-endian encoded array of bytes.
Automatically convert a value depending on the byte array size. If size if not a pow of two, the floor pow of two is filled (for example is size is 5, value will be considered as integer). byte[] of more than 8 bytes will be cropped. This function is a bridge to xxxToLEBytes and xxxToBEBytes functions.
bo | byteOrder to use for output value |
---|---|
v | input value |
output | output representation of v, using the given ByteOrder |
Convert a 16-bit integer to a big-endian encoded array of bytes.
Convert a 16-bit integer to a little-endian encoded array of bytes.
Flip the byte order of an array of bytes. This method does not create a new array.
array | the input/output array |
---|---|
offset | start index |
size | number of elements to flip |
Flip the byte order of an array of bytes. This method does not create a new array.
array | the input/output array |
---|
Flip the byte order of groups of bytes. This method does not create a new array.
array | byte array to change |
---|---|
grpByteCount | number of bytes per group (2 for 16 bits, 4 for 32 bits, 8 for 64 bits) |
Swap the byte ordering of an int.
Swap the byte ordering of a long.
Swap the byte ordering of a short.