Conversion¶
- public class org.apache.commons.lang3.Conversion[source]¶
Static methods to convert a type into another, with endianness and bit ordering awareness.
The methods names follow a naming rule:
<source type>[source endianness][source bit ordering]To<destination type>[destination endianness][destination bit ordering]
Source/destination type fields is one of the following:
binary: an array of booleans
byte or byteArray
int or intArray
long or longArray
hex: a String containing hexadecimal digits (lowercase in destination)
hexDigit: a
charcontaining a hexadecimal digit (lowercase in destination)uuid
Endianness field: little-endian is the default, in this case the field is absent. In case of big-endian, the field is “Be”.
Bit ordering: LSB0 is the default, in this case the field is absent. In case of MSB0, the field is “Msb0” (Camel-case).
Example: intBeMsb0ToHex convert an
intwith big-endian byte order and MSB0 bit order into its hexadecimal string representationMost of the methods provide only default encoding for destination, this limits the number of ways to do one thing. Unless you are dealing with data from/to outside of the JVM platform, you should not need to use “Be” and “Msb0” methods.
Development status: work on going, only a part of the little-endian, LSB0 methods implemented so far.
- Since:
3.2
Constructors¶
Deprecated. Constructs a new instance. |
- @Deprecated public Conversion()[source]¶
Deprecated: Will be removed in 4.0.0.
Constructs a new instance.
Methods¶
Converts the first 4 bits of a binary (represented as boolean array) in big-endian MSB0 bit ordering to a hexadecimal digit. |
|
Converts a binary (represented as boolean array) in big-endian MSB0 bit ordering to a hexadecimal digit. |
|
Converts binary (represented as boolean array) into a byte using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts binary (represented as boolean array) to a hexadecimal digit using the default (LSB0) bit ordering. |
|
Converts binary (represented as boolean array) to a hexadecimal digit using the default (LSB0) bit ordering. |
|
Converts binary (represented as boolean array) to a hexadecimal digit using the MSB0 bit ordering. |
|
Converts binary (represented as boolean array) to a hexadecimal digit using the MSB0 bit ordering. |
|
Converts binary (represented as boolean array) into an int using the default (little endian, LSB0) byte and bit ordering. |
|
Converts binary (represented as boolean array) into a long using the default (little endian, LSB0) byte and bit ordering. |
|
Converts binary (represented as boolean array) into a short using the default (little endian, LSB0) byte and bit ordering. |
|
Converts an array of byte into an int using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of byte into a long using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of byte into a short using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts bytes from an array into a UUID using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a byte into an array of boolean using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a byte into an array of char using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a hexadecimal digit into binary (represented as boolean array) using the MSB0 bit ordering. |
|
Converts a hexadecimal digit into an int using the MSB0 bit ordering. |
|
Converts a hexadecimal digit into binary (represented as boolean array) using the default (LSB0) bit ordering. |
|
Converts a hexadecimal digit into an int using the default (LSB0) bit ordering. |
|
Converts a hexadecimal string into a byte using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of char into an int using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of char into a long using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of char into a short using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of int into a long using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an int into an array of boolean using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an int into an array of byte using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an int into an array of char using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts the 4 LSB of an int to a hexadecimal digit. |
|
Converts the 4 LSB of an int to a hexadecimal digit encoded using the MSB0 bit ordering. |
|
Converts an int into an array of short using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a long into an array of boolean using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a long into an array of byte using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a long into an array of char using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a long into an array of int using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a long into an array of short using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of short into an int using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts an array of short into a long using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a short into an array of boolean using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a short into an array of byte using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts a short into an array of char using the default (little-endian, LSB0) byte and bit ordering. |
|
Converts UUID into an array of byte using the default (little-endian, LSB0) byte and bit ordering. |
- public static char binaryBeMsb0ToHexDigit(boolean[] src)[source]¶
Converts the first 4 bits of a binary (represented as boolean array) in big-endian MSB0 bit ordering to a hexadecimal digit.
(1, 0, 0, 0) is converted as follow: ‘8’ (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0) is converted to ‘4’.
- Parameters:
src – The binary to convert.
- Returns:
A hexadecimal digit representing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
srcis empty.java.lang.NullPointerException – Thrown if
srcisnull.
- public static char binaryBeMsb0ToHexDigit(boolean[] src, int srcPos)[source]¶
Converts a binary (represented as boolean array) in big-endian MSB0 bit ordering to a hexadecimal digit.
(1, 0, 0, 0) with srcPos = 0 is converted as follow: ‘8’ (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0) with srcPos = 2 is converted to ‘5’.
- Parameters:
src – The binary to convert.
srcPos – The position of the LSB to start the conversion.
- Returns:
A hexadecimal digit representing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
srcis empty.java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IndexOutOfBoundsException – Thrown if
srcPosis outside the array.
- public static byte binaryToByte(boolean[] src, int srcPos, byte dstInit, int dstPos, int nBools)[source]¶
Converts binary (represented as boolean array) into a byte using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The binary to convert.
srcPos – The position in
src, in boolean unit, from where to start the conversion.dstInit – initial value of the destination byte.
dstPos – The position of the LSB, in bits, in the result byte.
nBools – The number of booleans to convert.
- Returns:
A byte containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + dstPos >= 8.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nBools > src.length.
- public static char binaryToHexDigit(boolean[] src)[source]¶
Converts binary (represented as boolean array) to a hexadecimal digit using the default (LSB0) bit ordering.
(1, 0, 0, 0) is converted as follow: ‘1’.
- Parameters:
src – The binary to convert.
- Returns:
A hexadecimal digit representing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
srcis empty.java.lang.NullPointerException – Thrown if
srcisnull.
- public static char binaryToHexDigit(boolean[] src, int srcPos)[source]¶
Converts binary (represented as boolean array) to a hexadecimal digit using the default (LSB0) bit ordering.
(1, 0, 0, 0) is converted as follow: ‘1’.
- Parameters:
src – The binary to convert.
srcPos – The position of the LSB to start the conversion.
- Returns:
A hexadecimal digit representing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
srcis empty.java.lang.NullPointerException – Thrown if
srcisnull.
- public static char binaryToHexDigitMsb0_4bits(boolean[] src)[source]¶
Converts binary (represented as boolean array) to a hexadecimal digit using the MSB0 bit ordering.
(1, 0, 0, 0) is converted as follow: ‘8’.
- Parameters:
src – The binary to convert.
- Returns:
A hexadecimal digit representing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
srcis empty,src.length < 4orsrc.length > 8.java.lang.NullPointerException – Thrown if
srcisnull.
- public static char binaryToHexDigitMsb0_4bits(boolean[] src, int srcPos)[source]¶
Converts binary (represented as boolean array) to a hexadecimal digit using the MSB0 bit ordering.
(1, 0, 0, 0) is converted as follow: ‘8’ (1, 0, 0, 1, 1, 0, 1, 0) with srcPos = 3 is converted to ‘D’
- Parameters:
src – The binary to convert.
srcPos – The position of the LSB to start the conversion.
- Returns:
A hexadecimal digit representing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
srcis empty,src.length > 8orsrc.length - srcPos < 4.java.lang.NullPointerException – Thrown if
srcisnull.
- public static int binaryToInt(boolean[] src, int srcPos, int dstInit, int dstPos, int nBools)[source]¶
Converts binary (represented as boolean array) into an int using the default (little endian, LSB0) byte and bit ordering.
- Parameters:
src – The binary to convert.
srcPos – The position in
src, in boolean unit, from where to start the conversion.dstInit – initial value of the destination int.
dstPos – The position of the LSB, in bits, in the result int.
nBools – The number of booleans to convert.
- Returns:
An int containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + dstPos >= 32.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nBools > src.length.
- public static long binaryToLong(boolean[] src, int srcPos, long dstInit, int dstPos, int nBools)[source]¶
Converts binary (represented as boolean array) into a long using the default (little endian, LSB0) byte and bit ordering.
- Parameters:
src – The binary to convert.
srcPos – The position in
src, in boolean unit, from where to start the conversion.dstInit – initial value of the destination long.
dstPos – The position of the LSB, in bits, in the result long.
nBools – The number of booleans to convert.
- Returns:
A long containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + dstPos >= 64.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nBools > src.length.
- public static short binaryToShort(boolean[] src, int srcPos, short dstInit, int dstPos, int nBools)[source]¶
Converts binary (represented as boolean array) into a short using the default (little endian, LSB0) byte and bit ordering.
- Parameters:
src – The binary to convert.
srcPos – The position in
src, in boolean unit, from where to start the conversion.dstInit – initial value of the destination short.
dstPos – The position of the LSB, in bits, in the result short.
nBools – The number of booleans to convert.
- Returns:
A short containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + dstPos >= 16.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nBools > src.length.
- public static int byteArrayToInt(byte[] src, int srcPos, int dstInit, int dstPos, int nBytes)[source]¶
Converts an array of byte into an int using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The byte array to convert.
srcPos – The position in
src, in byte unit, from where to start the conversion.dstInit – initial value of the destination int.
dstPos – The position of the LSB, in bits, in the result int.
nBytes – The number of bytes to convert.
- Returns:
An int containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
(nBytes - 1) * 8 + dstPos >= 32.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nBytes > src.length.
- public static long byteArrayToLong(byte[] src, int srcPos, long dstInit, int dstPos, int nBytes)[source]¶
Converts an array of byte into a long using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The byte array to convert.
srcPos – The position in
src, in byte unit, from where to start the conversion.dstInit – initial value of the destination long.
dstPos – The position of the LSB, in bits, in the result long.
nBytes – The number of bytes to convert.
- Returns:
A long containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
(nBytes - 1) * 8 + dstPos >= 64.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nBytes > src.length.
- public static short byteArrayToShort(byte[] src, int srcPos, short dstInit, int dstPos, int nBytes)[source]¶
Converts an array of byte into a short using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The byte array to convert.
srcPos – The position in
src, in byte unit, from where to start the conversion.dstInit – initial value of the destination short.
dstPos – The position of the LSB, in bits, in the result short.
nBytes – The number of bytes to convert.
- Returns:
A short containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
(nBytes - 1) * 8 + dstPos >= 16.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nBytes > src.length.
- public static UUID byteArrayToUuid(byte[] src, int srcPos)[source]¶
Converts bytes from an array into a UUID using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The byte array to convert.
srcPos – The position in
srcwhere to copy the result from.
- Returns:
A UUID.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if array does not contain at least 16 bytes beginning with
srcPos.
- public static boolean[] byteToBinary(byte src, int srcPos, boolean[] dst, int dstPos, int nBools)[source]¶
Converts a byte into an array of boolean using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The byte to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBools – The number of booleans to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + srcPos >= 8.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBools > dst.length.
- public static String byteToHex(byte src, int srcPos, String dstInit, int dstPos, int nHexs)[source]¶
Converts a byte into an array of char using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The byte to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dstInit – The initial value for the result String.
dstPos – The position in
dstwhere to copy the result.nHexs – The number of chars to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHexs - 1) * 4 + srcPos >= 8.java.lang.StringIndexOutOfBoundsException – Thrown if
dst.init.length() < dstPos.
- public static boolean[] hexDigitMsb0ToBinary(char hexChar)[source]¶
Converts a hexadecimal digit into binary (represented as boolean array) using the MSB0 bit ordering.
‘1’ is converted as follow: (0, 0, 0, 1).
- Parameters:
hexChar – The hexadecimal digit to convert.
- Returns:
A boolean array with the binary representation of
hexDigit.- Throws:
java.lang.IllegalArgumentException – Thrown if
hexDigitis not a hexadecimal digit.
- public static int hexDigitMsb0ToInt(char hexChar)[source]¶
Converts a hexadecimal digit into an int using the MSB0 bit ordering.
‘1’ is converted to 8.
- Parameters:
hexChar – The hexadecimal digit to convert.
- Returns:
An int equals to
hexDigit.- Throws:
java.lang.IllegalArgumentException – Thrown if
hexDigitis not a hexadecimal digit.
- public static boolean[] hexDigitToBinary(char hexChar)[source]¶
Converts a hexadecimal digit into binary (represented as boolean array) using the default (LSB0) bit ordering.
‘1’ is converted as follow: (1, 0, 0, 0).
- Parameters:
hexChar – The hexadecimal digit to convert.
- Returns:
A boolean array with the binary representation of
hexDigit.- Throws:
java.lang.IllegalArgumentException – Thrown if
hexDigitis not a hexadecimal digit.
- public static int hexDigitToInt(char hexChar)[source]¶
Converts a hexadecimal digit into an int using the default (LSB0) bit ordering.
‘1’ is converted to 1.
- Parameters:
hexChar – The hexadecimal digit to convert.
- Returns:
An int equals to
hexDigit.- Throws:
java.lang.IllegalArgumentException – Thrown if
hexDigitis not a hexadecimal digit.
- public static byte hexToByte(String src, int srcPos, byte dstInit, int dstPos, int nHex)[source]¶
Converts a hexadecimal string into a byte using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The hexadecimal string to convert.
srcPos – The position in
src, in char unit, from where to start the conversion.dstInit – initial value of the destination byte.
dstPos – The position of the LSB, in bits, in the result byte.
nHex – The number of Chars to convert.
- Returns:
A byte containing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHex-1)*4+dstPos >= 8.
- public static int hexToInt(String src, int srcPos, int dstInit, int dstPos, int nHex)[source]¶
Converts an array of char into an int using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The hexadecimal string to convert.
srcPos – The position in
src, in char unit, from where to start the conversion.dstInit – initial value of the destination int.
dstPos – The position of the LSB, in bits, in the result int.
nHex – The number of chars to convert.
- Returns:
An int containing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHexs - 1) * 4 + dstPos >= 32.
- public static long hexToLong(String src, int srcPos, long dstInit, int dstPos, int nHex)[source]¶
Converts an array of char into a long using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The hexadecimal string to convert.
srcPos – The position in
src, in char unit, from where to start the conversion.dstInit – initial value of the destination long.
dstPos – The position of the LSB, in bits, in the result long.
nHex – The number of chars to convert.
- Returns:
A long containing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHexs - 1) * 4 + dstPos >= 64.
- public static short hexToShort(String src, int srcPos, short dstInit, int dstPos, int nHex)[source]¶
Converts an array of char into a short using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The hexadecimal string to convert.
srcPos – The position in
src, in char unit, from where to start the conversion.dstInit – initial value of the destination short.
dstPos – The position of the LSB, in bits, in the result short.
nHex – The number of chars to convert.
- Returns:
A short containing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHexs - 1) * 4 + dstPos >= 16.
- public static long intArrayToLong(int[] src, int srcPos, long dstInit, int dstPos, int nInts)[source]¶
Converts an array of int into a long using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The int array to convert.
srcPos – The position in
src, in int unit, from where to start the conversion.dstInit – initial value of the destination long.
dstPos – The position of the LSB, in bits, in the result long.
nInts – The number of ints to convert.
- Returns:
A long containing the selected bits.
- Throws:
java.lang.IllegalArgumentException – Thrown if
(nInts - 1) * 32 + dstPos >= 64.java.lang.NullPointerException – Thrown if
srcisnull.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nInts > src.length.
- public static boolean[] intToBinary(int src, int srcPos, boolean[] dst, int dstPos, int nBools)[source]¶
Converts an int into an array of boolean using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The int to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBools – The number of booleans to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + srcPos >= 32.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBools > dst.length.
- public static byte[] intToByteArray(int src, int srcPos, byte[] dst, int dstPos, int nBytes)[source]¶
Converts an int into an array of byte using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The int to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBytes – The number of bytes to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
(nBytes - 1) * 8 + srcPos >= 32.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBytes > dst.length.
- public static String intToHex(int src, int srcPos, String dstInit, int dstPos, int nHexs)[source]¶
Converts an int into an array of char using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The int to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dstInit – The initial value for the result String.
dstPos – The position in
dstwhere to copy the result.nHexs – The number of chars to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHexs - 1) * 4 + srcPos >= 32.java.lang.StringIndexOutOfBoundsException – Thrown if
dst.init.length() < dstPos.
- public static char intToHexDigit(int nibble)[source]¶
Converts the 4 LSB of an int to a hexadecimal digit.
0 returns ‘0’
1 returns ‘1’
10 returns ‘A’ and so on…
- Parameters:
nibble – The 4 bits to convert.
- Returns:
A hexadecimal digit representing the 4 LSB of
nibble.- Throws:
java.lang.IllegalArgumentException – Thrown if
nibble < 0ornibble > 15.
- public static char intToHexDigitMsb0(int nibble)[source]¶
Converts the 4 LSB of an int to a hexadecimal digit encoded using the MSB0 bit ordering.
0 returns ‘0’
1 returns ‘8’
10 returns ‘5’ and so on…
- Parameters:
nibble – The 4 bits to convert.
- Returns:
A hexadecimal digit representing the 4 LSB of
nibble.- Throws:
java.lang.IllegalArgumentException – Thrown if
nibble < 0ornibble > 15.
- public static short[] intToShortArray(int src, int srcPos, short[] dst, int dstPos, int nShorts)[source]¶
Converts an int into an array of short using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The int to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nShorts – The number of shorts to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
(nShorts - 1) * 16 + srcPos >= 32.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nShorts > dst.length.
- public static boolean[] longToBinary(long src, int srcPos, boolean[] dst, int dstPos, int nBools)[source]¶
Converts a long into an array of boolean using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The long to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBools – The number of booleans to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + srcPos >= 64.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBools > dst.length.
- public static byte[] longToByteArray(long src, int srcPos, byte[] dst, int dstPos, int nBytes)[source]¶
Converts a long into an array of byte using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The long to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBytes – The number of bytes to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
(nBytes - 1) * 8 + srcPos >= 64.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBytes > dst.length.
- public static String longToHex(long src, int srcPos, String dstInit, int dstPos, int nHexs)[source]¶
Converts a long into an array of char using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The long to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dstInit – The initial value for the result String.
dstPos – The position in
dstwhere to copy the result.nHexs – The number of chars to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHexs - 1) * 4 + srcPos >= 64.java.lang.StringIndexOutOfBoundsException – Thrown if
dst.init.length() < dstPos.
- public static int[] longToIntArray(long src, int srcPos, int[] dst, int dstPos, int nInts)[source]¶
Converts a long into an array of int using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The long to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nInts – The number of ints to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnullandnInts > 0.java.lang.IllegalArgumentException – Thrown if
(nInts - 1) * 32 + srcPos >= 64.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nInts > dst.length.
- public static short[] longToShortArray(long src, int srcPos, short[] dst, int dstPos, int nShorts)[source]¶
Converts a long into an array of short using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The long to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nShorts – The number of shorts to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
(nShorts - 1) * 16 + srcPos >= 64.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nShorts > dst.length.
- public static int shortArrayToInt(short[] src, int srcPos, int dstInit, int dstPos, int nShorts)[source]¶
Converts an array of short into an int using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The short array to convert.
srcPos – The position in
src, in short unit, from where to start the conversion.dstInit – initial value of the destination int.
dstPos – The position of the LSB, in bits, in the result int.
nShorts – The number of shorts to convert.
- Returns:
An int containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
(nShorts - 1) * 16 + dstPos >= 32.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nShorts > src.length.
- public static long shortArrayToLong(short[] src, int srcPos, long dstInit, int dstPos, int nShorts)[source]¶
Converts an array of short into a long using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The short array to convert.
srcPos – The position in
src, in short unit, from where to start the conversion.dstInit – initial value of the destination long.
dstPos – The position of the LSB, in bits, in the result long.
nShorts – The number of shorts to convert.
- Returns:
A long containing the selected bits.
- Throws:
java.lang.NullPointerException – Thrown if
srcisnull.java.lang.IllegalArgumentException – Thrown if
(nShorts - 1) * 16 + dstPos >= 64.java.lang.ArrayIndexOutOfBoundsException – Thrown if
srcPos + nShorts > src.length.
- public static boolean[] shortToBinary(short src, int srcPos, boolean[] dst, int dstPos, int nBools)[source]¶
Converts a short into an array of boolean using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The short to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBools – The number of booleans to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
nBools - 1 + srcPos >= 16.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBools > dst.length.
- public static byte[] shortToByteArray(short src, int srcPos, byte[] dst, int dstPos, int nBytes)[source]¶
Converts a short into an array of byte using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The short to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBytes – The number of bytes to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
(nBytes - 1) * 8 + srcPos >= 16.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBytes > dst.length.
- public static String shortToHex(short src, int srcPos, String dstInit, int dstPos, int nHexs)[source]¶
Converts a short into an array of char using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The short to convert.
srcPos – The position in
src, in bits, from where to start the conversion.dstInit – The initial value for the result String.
dstPos – The position in
dstwhere to copy the result.nHexs – The number of chars to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.IllegalArgumentException – Thrown if
(nHexs - 1) * 4 + srcPos >= 16.java.lang.StringIndexOutOfBoundsException – Thrown if
dst.init.length() < dstPos.
- public static byte[] uuidToByteArray(UUID src, byte[] dst, int dstPos, int nBytes)[source]¶
Converts UUID into an array of byte using the default (little-endian, LSB0) byte and bit ordering.
- Parameters:
src – The UUID to convert.
dst – The destination array.
dstPos – The position in
dstwhere to copy the result.nBytes – The number of bytes to copy to
dst, must be smaller or equal to the width of the input (from srcPos to MSB).
- Returns:
dst.- Throws:
java.lang.NullPointerException – Thrown if
dstisnull.java.lang.IllegalArgumentException – Thrown if
nBytes > 16.java.lang.ArrayIndexOutOfBoundsException – Thrown if
dstPos + nBytes > dst.length.