public class Conversion extends Object
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:
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".
Example: intBeMsb0ToHex convert an int with big endian byte order and Msb0 bit order into its hexadecimal string representation
Most 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.
Constructor and Description |
---|
Conversion() |
Modifier and Type | Method and Description |
---|---|
static char |
binaryBeMsb0ToHexDigit(boolean[] src)
Converts the first 4 bits of a binary (represented as boolean array) in big endian Msb0
bit ordering to a hexadecimal digit.
|
static char |
binaryBeMsb0ToHexDigit(boolean[] src,
int srcPos)
Converts a binary (represented as boolean array) in big endian Msb0 bit ordering to a
hexadecimal digit.
|
static byte |
binaryToByte(boolean[] src,
int srcPos,
byte dstInit,
int dstPos,
int nBools)
Converts binary (represented as boolean array) into a byte using the default (little
endian, Lsb0) byte and bit ordering.
|
static char |
binaryToHexDigit(boolean[] src)
Converts binary (represented as boolean array) to a hexadecimal digit using the default
(Lsb0) bit ordering.
|
static char |
binaryToHexDigit(boolean[] src,
int srcPos)
Converts binary (represented as boolean array) to a hexadecimal digit using the default
(Lsb0) bit ordering.
|
static char |
binaryToHexDigitMsb0_4bits(boolean[] src)
Converts binary (represented as boolean array) to a hexadecimal digit using the Msb0 bit
ordering.
|
static char |
binaryToHexDigitMsb0_4bits(boolean[] src,
int srcPos)
Converts binary (represented as boolean array) to a hexadecimal digit using the Msb0 bit
ordering.
|
static int |
binaryToInt(boolean[] src,
int srcPos,
int dstInit,
int dstPos,
int nBools)
Converts binary (represented as boolean array) into an int using the default (little
endian, Lsb0) byte and bit ordering.
|
static long |
binaryToLong(boolean[] src,
int srcPos,
long dstInit,
int dstPos,
int nBools)
Converts binary (represented as boolean array) into a long using the default (little
endian, Lsb0) byte and bit ordering.
|
static short |
binaryToShort(boolean[] src,
int srcPos,
short dstInit,
int dstPos,
int nBools)
Converts binary (represented as boolean array) into a short using the default (little
endian, Lsb0) byte and bit ordering.
|
static int |
byteArrayToInt(byte[] src,
int srcPos,
int dstInit,
int dstPos,
int nBytes)
Converts an array of byte into an int using the default (little endian, Lsb0) byte and bit
ordering.
|
static long |
byteArrayToLong(byte[] src,
int srcPos,
long dstInit,
int dstPos,
int nBytes)
Converts an array of byte into a long using the default (little endian, Lsb0) byte and
bit ordering.
|
static short |
byteArrayToShort(byte[] src,
int srcPos,
short dstInit,
int dstPos,
int nBytes)
Converts an array of byte into a short using the default (little endian, Lsb0) byte and
bit ordering.
|
static UUID |
byteArrayToUuid(byte[] src,
int srcPos)
Converts bytes from an array into a UUID using the default (little endian, Lsb0) byte and
bit ordering.
|
static boolean[] |
byteToBinary(byte src,
int srcPos,
boolean[] dst,
int dstPos,
int nBools)
Converts a byte into an array of boolean using the default (little endian, Lsb0) byte and
bit ordering.
|
static String |
byteToHex(byte src,
int srcPos,
String dstInit,
int dstPos,
int nHexs)
Converts a byte into an array of Char using the default (little endian, Lsb0) byte and
bit ordering.
|
static boolean[] |
hexDigitMsb0ToBinary(char hexDigit)
Converts a hexadecimal digit into binary (represented as boolean array) using the Msb0
bit ordering.
|
static int |
hexDigitMsb0ToInt(char hexDigit)
Converts a hexadecimal digit into an int using the Msb0 bit ordering.
|
static boolean[] |
hexDigitToBinary(char hexDigit)
Converts a hexadecimal digit into binary (represented as boolean array) using the default
(Lsb0) bit ordering.
|
static int |
hexDigitToInt(char hexDigit)
Converts a hexadecimal digit into an int using the default (Lsb0) bit ordering.
|
static byte |
hexToByte(String src,
int srcPos,
byte dstInit,
int dstPos,
int nHex)
Converts an array of Char into a byte using the default (little endian, Lsb0) byte and
bit ordering.
|
static int |
hexToInt(String src,
int srcPos,
int dstInit,
int dstPos,
int nHex)
Converts an array of Char into an int using the default (little endian, Lsb0) byte and bit
ordering.
|
static long |
hexToLong(String src,
int srcPos,
long dstInit,
int dstPos,
int nHex)
Converts an array of Char into a long using the default (little endian, Lsb0) byte and
bit ordering.
|
static short |
hexToShort(String src,
int srcPos,
short dstInit,
int dstPos,
int nHex)
Converts an array of Char into a short using the default (little endian, Lsb0) byte and
bit ordering.
|
static long |
intArrayToLong(int[] src,
int srcPos,
long dstInit,
int dstPos,
int nInts)
Converts an array of int into a long using the default (little endian, Lsb0) byte and bit
ordering.
|
static boolean[] |
intToBinary(int src,
int srcPos,
boolean[] dst,
int dstPos,
int nBools)
Converts an int into an array of boolean using the default (little endian, Lsb0) byte and
bit ordering.
|
static byte[] |
intToByteArray(int src,
int srcPos,
byte[] dst,
int dstPos,
int nBytes)
Converts an int into an array of byte using the default (little endian, Lsb0) byte and bit
ordering.
|
static String |
intToHex(int src,
int srcPos,
String dstInit,
int dstPos,
int nHexs)
Converts an int into an array of Char using the default (little endian, Lsb0) byte and bit
ordering.
|
static char |
intToHexDigit(int nibble)
Converts the 4 lsb of an int to a hexadecimal digit.
|
static char |
intToHexDigitMsb0(int nibble)
Converts the 4 lsb of an int to a hexadecimal digit encoded using the Msb0 bit ordering.
|
static short[] |
intToShortArray(int src,
int srcPos,
short[] dst,
int dstPos,
int nShorts)
Converts an int into an array of short using the default (little endian, Lsb0) byte and
bit ordering.
|
static boolean[] |
longToBinary(long src,
int srcPos,
boolean[] dst,
int dstPos,
int nBools)
Converts a long into an array of boolean using the default (little endian, Lsb0) byte and
bit ordering.
|
static byte[] |
longToByteArray(long src,
int srcPos,
byte[] dst,
int dstPos,
int nBytes)
Converts a long into an array of byte using the default (little endian, Lsb0) byte and
bit ordering.
|
static String |
longToHex(long src,
int srcPos,
String dstInit,
int dstPos,
int nHexs)
Converts a long into an array of Char using the default (little endian, Lsb0) byte and
bit ordering.
|
static int[] |
longToIntArray(long src,
int srcPos,
int[] dst,
int dstPos,
int nInts)
Converts a long into an array of int using the default (little endian, Lsb0) byte and bit
ordering.
|
static short[] |
longToShortArray(long src,
int srcPos,
short[] dst,
int dstPos,
int nShorts)
Converts a long into an array of short using the default (little endian, Lsb0) byte and
bit ordering.
|
static int |
shortArrayToInt(short[] src,
int srcPos,
int dstInit,
int dstPos,
int nShorts)
Converts an array of short into an int using the default (little endian, Lsb0) byte and
bit ordering.
|
static long |
shortArrayToLong(short[] src,
int srcPos,
long dstInit,
int dstPos,
int nShorts)
Converts an array of short into a long using the default (little endian, Lsb0) byte and
bit ordering.
|
static boolean[] |
shortToBinary(short src,
int srcPos,
boolean[] dst,
int dstPos,
int nBools)
Converts a short into an array of boolean using the default (little endian, Lsb0) byte
and bit ordering.
|
static byte[] |
shortToByteArray(short src,
int srcPos,
byte[] dst,
int dstPos,
int nBytes)
Converts a short into an array of byte using the default (little endian, Lsb0) byte and
bit ordering.
|
static String |
shortToHex(short src,
int srcPos,
String dstInit,
int dstPos,
int nHexs)
Converts a short into an array of Char using the default (little endian, Lsb0) byte and
bit ordering.
|
static byte[] |
uuidToByteArray(UUID src,
byte[] dst,
int dstPos,
int nBytes)
Converts UUID into an array of byte using the default (little endian, Lsb0) byte and bit
ordering.
|
public Conversion()
public static int hexDigitToInt(char hexDigit)
Converts a hexadecimal digit into an int using the default (Lsb0) bit ordering.
'1' is converted to 1
hexDigit
- the hexadecimal digit to converthexDigit
IllegalArgumentException
- if hexDigit
is not a hexadecimal digitpublic static int hexDigitMsb0ToInt(char hexDigit)
Converts a hexadecimal digit into an int using the Msb0 bit ordering.
'1' is converted to 8
hexDigit
- the hexadecimal digit to converthexDigit
IllegalArgumentException
- if hexDigit
is not a hexadecimal digitpublic static boolean[] hexDigitToBinary(char hexDigit)
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)
hexDigit
- the hexadecimal digit to converthexDigit
IllegalArgumentException
- if hexDigit
is not a hexadecimal digitpublic static boolean[] hexDigitMsb0ToBinary(char hexDigit)
Converts a hexadecimal digit into binary (represented as boolean array) using the Msb0 bit ordering.
'1' is converted as follow: (0, 0, 0, 1)
hexDigit
- the hexadecimal digit to converthexDigit
IllegalArgumentException
- if hexDigit
is not a hexadecimal digitpublic static char binaryToHexDigit(boolean[] src)
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'
src
- the binary to convertIllegalArgumentException
- if src
is emptyNullPointerException
- if src
is null
public static char binaryToHexDigit(boolean[] src, int srcPos)
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'
src
- the binary to convertsrcPos
- the position of the lsb to start the conversionIllegalArgumentException
- if src
is emptyNullPointerException
- if src
is null
public static char binaryToHexDigitMsb0_4bits(boolean[] src)
Converts binary (represented as boolean array) to a hexadecimal digit using the Msb0 bit ordering.
(1, 0, 0, 0) is converted as follow: '8'
src
- the binary to convertIllegalArgumentException
- if src
is empty, src.length < 4
or
src.length > 8
NullPointerException
- if src
is null
public static char binaryToHexDigitMsb0_4bits(boolean[] src, int srcPos)
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'
src
- the binary to convertsrcPos
- the position of the lsb to start the conversionIllegalArgumentException
- if src
is empty, src.length > 8
or
src.length - srcPos < 4
NullPointerException
- if src
is null
public static char binaryBeMsb0ToHexDigit(boolean[] src)
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'
src
- the binary to convertIllegalArgumentException
- if src
is emptyNullPointerException
- if src
is null
public static char binaryBeMsb0ToHexDigit(boolean[] src, int srcPos)
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'
src
- the binary to convertsrcPos
- the position of the lsb to start the conversionIllegalArgumentException
- if src
is emptyNullPointerException
- if src
is null
public static char intToHexDigit(int nibble)
Converts the 4 lsb of an int to a hexadecimal digit.
0 returns '0'
1 returns '1'
10 returns 'A' and so on...
nibble
- the 4 bits to convertnibble
IllegalArgumentException
- if nibble < 0
or nibble > 15
public static char intToHexDigitMsb0(int nibble)
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...
nibble
- the 4 bits to convertnibble
IllegalArgumentException
- if nibble < 0
or nibble > 15
public static long intArrayToLong(int[] src, int srcPos, long dstInit, int dstPos, int nInts)
Converts an array of int into a long using the default (little endian, Lsb0) byte and bit ordering.
src
- the int array to convertsrcPos
- the position in src
, in int unit, from where to start the
conversiondstInit
- initial value of the destination longdstPos
- the position of the lsb, in bits, in the result longnInts
- the number of ints to convertIllegalArgumentException
- if (nInts-1)*32+dstPos >= 64
NullPointerException
- if src
is null
ArrayIndexOutOfBoundsException
- if srcPos + nInts > src.length
public static long shortArrayToLong(short[] src, int srcPos, long dstInit, int dstPos, int nShorts)
Converts an array of short into a long using the default (little endian, Lsb0) byte and bit ordering.
src
- the short array to convertsrcPos
- the position in src
, in short unit, from where to start the
conversiondstInit
- initial value of the destination longdstPos
- the position of the lsb, in bits, in the result longnShorts
- the number of shorts to convertNullPointerException
- if src
is null
IllegalArgumentException
- if (nShorts-1)*16+dstPos >= 64
ArrayIndexOutOfBoundsException
- if srcPos + nShorts > src.length
public static int shortArrayToInt(short[] src, int srcPos, int dstInit, int dstPos, int nShorts)
Converts an array of short into an int using the default (little endian, Lsb0) byte and bit ordering.
src
- the short array to convertsrcPos
- the position in src
, in short unit, from where to start the
conversiondstInit
- initial value of the destination intdstPos
- the position of the lsb, in bits, in the result intnShorts
- the number of shorts to convertNullPointerException
- if src
is null
IllegalArgumentException
- if (nShorts-1)*16+dstPos >= 32
ArrayIndexOutOfBoundsException
- if srcPos + nShorts > src.length
public static long byteArrayToLong(byte[] src, int srcPos, long dstInit, int dstPos, int nBytes)
Converts an array of byte into a long using the default (little endian, Lsb0) byte and bit ordering.
src
- the byte array to convertsrcPos
- the position in src
, in byte unit, from where to start the
conversiondstInit
- initial value of the destination longdstPos
- the position of the lsb, in bits, in the result longnBytes
- the number of bytes to convertNullPointerException
- if src
is null
IllegalArgumentException
- if (nBytes-1)*8+dstPos >= 64
ArrayIndexOutOfBoundsException
- if srcPos + nBytes > src.length
public static int byteArrayToInt(byte[] src, int srcPos, int dstInit, int dstPos, int nBytes)
Converts an array of byte into an int using the default (little endian, Lsb0) byte and bit ordering.
src
- the byte array to convertsrcPos
- the position in src
, in byte unit, from where to start the
conversiondstInit
- initial value of the destination intdstPos
- the position of the lsb, in bits, in the result intnBytes
- the number of bytes to convertNullPointerException
- if src
is null
IllegalArgumentException
- if (nBytes-1)*8+dstPos >= 32
ArrayIndexOutOfBoundsException
- if srcPos + nBytes > src.length
public static short byteArrayToShort(byte[] src, int srcPos, short dstInit, int dstPos, int nBytes)
Converts an array of byte into a short using the default (little endian, Lsb0) byte and bit ordering.
src
- the byte array to convertsrcPos
- the position in src
, in byte unit, from where to start the
conversiondstInit
- initial value of the destination shortdstPos
- the position of the lsb, in bits, in the result shortnBytes
- the number of bytes to convertNullPointerException
- if src
is null
IllegalArgumentException
- if (nBytes-1)*8+dstPos >= 16
ArrayIndexOutOfBoundsException
- if srcPos + nBytes > src.length
public static long hexToLong(String src, int srcPos, long dstInit, int dstPos, int nHex)
Converts an array of Char into a long using the default (little endian, Lsb0) byte and bit ordering.
src
- the hex string to convertsrcPos
- the position in src
, in Char unit, from where to start the
conversiondstInit
- initial value of the destination longdstPos
- the position of the lsb, in bits, in the result longnHex
- the number of Chars to convertIllegalArgumentException
- if (nHexs-1)*4+dstPos >= 64
public static int hexToInt(String src, int srcPos, int dstInit, int dstPos, int nHex)
Converts an array of Char into an int using the default (little endian, Lsb0) byte and bit ordering.
src
- the hex string to convertsrcPos
- the position in src
, in Char unit, from where to start the
conversiondstInit
- initial value of the destination intdstPos
- the position of the lsb, in bits, in the result intnHex
- the number of Chars to convertIllegalArgumentException
- if (nHexs-1)*4+dstPos >= 32
public static short hexToShort(String src, int srcPos, short dstInit, int dstPos, int nHex)
Converts an array of Char into a short using the default (little endian, Lsb0) byte and bit ordering.
src
- the hex string to convertsrcPos
- the position in src
, in Char unit, from where to start the
conversiondstInit
- initial value of the destination shortdstPos
- the position of the lsb, in bits, in the result shortnHex
- the number of Chars to convertIllegalArgumentException
- if (nHexs-1)*4+dstPos >= 16
public static byte hexToByte(String src, int srcPos, byte dstInit, int dstPos, int nHex)
Converts an array of Char into a byte using the default (little endian, Lsb0) byte and bit ordering.
src
- the hex string to convertsrcPos
- the position in src
, in Char unit, from where to start the
conversiondstInit
- initial value of the destination bytedstPos
- the position of the lsb, in bits, in the result bytenHex
- the number of Chars to convertIllegalArgumentException
- if (nHexs-1)*4+dstPos >= 8
public static long binaryToLong(boolean[] src, int srcPos, long dstInit, int dstPos, int nBools)
Converts binary (represented as boolean array) into a long using the default (little endian, Lsb0) byte and bit ordering.
src
- the binary to convertsrcPos
- the position in src
, in boolean unit, from where to start the
conversiondstInit
- initial value of the destination longdstPos
- the position of the lsb, in bits, in the result longnBools
- the number of booleans to convertNullPointerException
- if src
is null
IllegalArgumentException
- if nBools-1+dstPos >= 64
ArrayIndexOutOfBoundsException
- if srcPos + nBools > src.length
public static int binaryToInt(boolean[] src, int srcPos, int dstInit, int dstPos, int nBools)
Converts binary (represented as boolean array) into an int using the default (little endian, Lsb0) byte and bit ordering.
src
- the binary to convertsrcPos
- the position in src
, in boolean unit, from where to start the
conversiondstInit
- initial value of the destination intdstPos
- the position of the lsb, in bits, in the result intnBools
- the number of booleans to convertNullPointerException
- if src
is null
IllegalArgumentException
- if nBools-1+dstPos >= 32
ArrayIndexOutOfBoundsException
- if srcPos + nBools > src.length
public static short binaryToShort(boolean[] src, int srcPos, short dstInit, int dstPos, int nBools)
Converts binary (represented as boolean array) into a short using the default (little endian, Lsb0) byte and bit ordering.
src
- the binary to convertsrcPos
- the position in src
, in boolean unit, from where to start the
conversiondstInit
- initial value of the destination shortdstPos
- the position of the lsb, in bits, in the result shortnBools
- the number of booleans to convertNullPointerException
- if src
is null
IllegalArgumentException
- if nBools-1+dstPos >= 16
ArrayIndexOutOfBoundsException
- if srcPos + nBools > src.length
public static byte binaryToByte(boolean[] src, int srcPos, byte dstInit, int dstPos, int nBools)
Converts binary (represented as boolean array) into a byte using the default (little endian, Lsb0) byte and bit ordering.
src
- the binary to convertsrcPos
- the position in src
, in boolean unit, from where to start the
conversiondstInit
- initial value of the destination bytedstPos
- the position of the lsb, in bits, in the result bytenBools
- the number of booleans to convertNullPointerException
- if src
is null
IllegalArgumentException
- if nBools-1+dstPos >= 8
ArrayIndexOutOfBoundsException
- if srcPos + nBools > src.length
public static int[] longToIntArray(long src, int srcPos, int[] dst, int dstPos, int nInts)
Converts a long into an array of int using the default (little endian, Lsb0) byte and bit ordering.
src
- the long to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnInts
- the number of ints to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
and nInts > 0
IllegalArgumentException
- if (nInts-1)*32+srcPos >= 64
ArrayIndexOutOfBoundsException
- if dstPos + nInts > dst.length
public static short[] longToShortArray(long src, int srcPos, short[] dst, int dstPos, int nShorts)
Converts a long into an array of short using the default (little endian, Lsb0) byte and bit ordering.
src
- the long to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnShorts
- the number of shorts to copy to dst
, must be smaller or equal to
the width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if (nShorts-1)*16+srcPos >= 64
ArrayIndexOutOfBoundsException
- if dstPos + nShorts > dst.length
public static short[] intToShortArray(int src, int srcPos, short[] dst, int dstPos, int nShorts)
Converts an int into an array of short using the default (little endian, Lsb0) byte and bit ordering.
src
- the int to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnShorts
- the number of shorts to copy to dst
, must be smaller or equal to
the width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if (nShorts-1)*16+srcPos >= 32
ArrayIndexOutOfBoundsException
- if dstPos + nShorts > dst.length
public static byte[] longToByteArray(long src, int srcPos, byte[] dst, int dstPos, int nBytes)
Converts a long into an array of byte using the default (little endian, Lsb0) byte and bit ordering.
src
- the long to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnBytes
- the number of bytes to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if (nBytes-1)*8+srcPos >= 64
ArrayIndexOutOfBoundsException
- if dstPos + nBytes > dst.length
public static byte[] intToByteArray(int src, int srcPos, byte[] dst, int dstPos, int nBytes)
Converts an int into an array of byte using the default (little endian, Lsb0) byte and bit ordering.
src
- the int to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnBytes
- the number of bytes to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if (nBytes-1)*8+srcPos >= 32
ArrayIndexOutOfBoundsException
- if dstPos + nBytes > dst.length
public static byte[] shortToByteArray(short src, int srcPos, byte[] dst, int dstPos, int nBytes)
Converts a short into an array of byte using the default (little endian, Lsb0) byte and bit ordering.
src
- the short to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnBytes
- the number of bytes to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if (nBytes-1)*8+srcPos >= 16
ArrayIndexOutOfBoundsException
- if dstPos + nBytes > dst.length
public static String longToHex(long src, int srcPos, String dstInit, int dstPos, int nHexs)
Converts a long into an array of Char using the default (little endian, Lsb0) byte and bit ordering.
src
- the long to convertsrcPos
- the position in src
, in bits, from where to start the conversiondstInit
- the initial value for the result StringdstPos
- the position in dst
where to copy the resultnHexs
- the number of Chars to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
IllegalArgumentException
- if (nHexs-1)*4+srcPos >= 64
StringIndexOutOfBoundsException
- if dst.init.length() < dstPos
public static String intToHex(int src, int srcPos, String dstInit, int dstPos, int nHexs)
Converts an int into an array of Char using the default (little endian, Lsb0) byte and bit ordering.
src
- the int to convertsrcPos
- the position in src
, in bits, from where to start the conversiondstInit
- the initial value for the result StringdstPos
- the position in dst
where to copy the resultnHexs
- the number of Chars to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
IllegalArgumentException
- if (nHexs-1)*4+srcPos >= 32
StringIndexOutOfBoundsException
- if dst.init.length() < dstPos
public static String shortToHex(short src, int srcPos, String dstInit, int dstPos, int nHexs)
Converts a short into an array of Char using the default (little endian, Lsb0) byte and bit ordering.
src
- the short to convertsrcPos
- the position in src
, in bits, from where to start the conversiondstInit
- the initial value for the result StringdstPos
- the position in dst
where to copy the resultnHexs
- the number of Chars to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
IllegalArgumentException
- if (nHexs-1)*4+srcPos >= 16
StringIndexOutOfBoundsException
- if dst.init.length() < dstPos
public static String byteToHex(byte src, int srcPos, String dstInit, int dstPos, int nHexs)
Converts a byte into an array of Char using the default (little endian, Lsb0) byte and bit ordering.
src
- the byte to convertsrcPos
- the position in src
, in bits, from where to start the conversiondstInit
- the initial value for the result StringdstPos
- the position in dst
where to copy the resultnHexs
- the number of Chars to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
IllegalArgumentException
- if (nHexs-1)*4+srcPos >= 8
StringIndexOutOfBoundsException
- if dst.init.length() < dstPos
public static boolean[] longToBinary(long src, int srcPos, boolean[] dst, int dstPos, int nBools)
Converts a long into an array of boolean using the default (little endian, Lsb0) byte and bit ordering.
src
- the long to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnBools
- the number of booleans to copy to dst
, must be smaller or equal to
the width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if nBools-1+srcPos >= 64
ArrayIndexOutOfBoundsException
- if dstPos + nBools > dst.length
public static boolean[] intToBinary(int src, int srcPos, boolean[] dst, int dstPos, int nBools)
Converts an int into an array of boolean using the default (little endian, Lsb0) byte and bit ordering.
src
- the int to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnBools
- the number of booleans to copy to dst
, must be smaller or equal to
the width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if nBools-1+srcPos >= 32
ArrayIndexOutOfBoundsException
- if dstPos + nBools > dst.length
public static boolean[] shortToBinary(short src, int srcPos, boolean[] dst, int dstPos, int nBools)
Converts a short into an array of boolean using the default (little endian, Lsb0) byte and bit ordering.
src
- the short to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnBools
- the number of booleans to copy to dst
, must be smaller or equal to
the width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if nBools-1+srcPos >= 16
ArrayIndexOutOfBoundsException
- if dstPos + nBools > dst.length
public static boolean[] byteToBinary(byte src, int srcPos, boolean[] dst, int dstPos, int nBools)
Converts a byte into an array of boolean using the default (little endian, Lsb0) byte and bit ordering.
src
- the byte to convertsrcPos
- the position in src
, in bits, from where to start the conversiondst
- the destination arraydstPos
- the position in dst
where to copy the resultnBools
- the number of booleans to copy to dst
, must be smaller or equal to
the width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if nBools-1+srcPos >= 8
ArrayIndexOutOfBoundsException
- if dstPos + nBools > dst.length
public static byte[] uuidToByteArray(UUID src, byte[] dst, int dstPos, int nBytes)
Converts UUID into an array of byte using the default (little endian, Lsb0) byte and bit ordering.
src
- the UUID to convertdst
- the destination arraydstPos
- the position in dst
where to copy the resultnBytes
- the number of bytes to copy to dst
, must be smaller or equal to the
width of the input (from srcPos to msb)dst
NullPointerException
- if dst
is null
IllegalArgumentException
- if nBytes > 16
ArrayIndexOutOfBoundsException
- if dstPos + nBytes > dst.length
public static UUID byteArrayToUuid(byte[] src, int srcPos)
Converts bytes from an array into a UUID using the default (little endian, Lsb0) byte and bit ordering.
src
- the byte array to convertsrcPos
- the position in src
where to copy the result fromNullPointerException
- if src
is null
IllegalArgumentException
- if array does not contain at least 16 bytes beginning
with srcPos
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.