Class Hex
-
- All Implemented Interfaces:
public class HexCreated by Sebastien_Tosello on 18/07/2016. Class qui provient de la 1.8.4 de parse
-
-
Constructor Summary
Constructors Constructor Description Hex()
-
Method Summary
Modifier and Type Method Description static Array<byte>decodeHex(Array<char> data)static Array<char>encodeHex(Array<byte> data)Encode a byte array into a char array. static Array<char>encodeHex(Array<byte> data, boolean toLowerCase)Encode a byte array into a char array. static StringencodeHexString(Array<byte> data)Converts a byte array into an hexadecimal string static Array<byte>convertTextToData(String text)Convert String to byte [] static StringbytesToHexString(Array<byte> array, int bufSize)Convert array of bytes into a hexadecimal string static StringbyteArrayToHexString(Array<byte> array, int size)static List<Byte>byteArrayToByteArray(Array<byte> data)Convert a byte array to a List of Byte. static StringbyteArrayToHexString(List<Byte> data)Convert a List of Byte to a String. static StringbyteArrayToHexString(Array<byte> a)Convert array of bytes into a hexadecimal string static StringbyteArrayToBitString(Array<byte> a)Convert array of bytes into a binary string of 0s and 1s static StringbinToHexString(String binaries)static StringbyteToHex(byte b)Converts a byte into hexadecimal value static StringbyteToBitString(byte n)Converts a byte into binary string static bytehexToByte(String s)Converts a hexadecimal String value into a byte static Array<byte>hexStringToByteArray(String s)Convert a String to a byte array static List<Byte>hexStringToByteArrayList(String hexData)Convert a hex data hosted in a string to List of Byte static Array<byte>binaryStringToByteArray(String stream, boolean roundUpperByte)Converts a string of 0s and 1s to a byte array. static Array<byte>binaryStringToByteArray(String stream)Converts a string of 0s and 1s to a byte array. static Array<byte>byteListToByteArray(List<Byte> blist)Helper method to convert a list of bytes to an array static StringtryParseIntToHex(String s)Convert a String representing an integer to Hexadecimal String with default value static StringinvertBitString(String data)Invert the bits in binary string. static booleancontainsOnlyHex(String data)Check if there is only hexadecimal digits (upper or lower case) in string. static booleancontainsOnlyBits(String data)Check if there is only 0/1 bits in binary string. static bytecountNumTrailingBitsInByte(byte data, boolean polarity)Return number of trailing bits of polarity set in byte data Ex: (0xE0, false): number of trailing bits set to 0 => 5 Ex: (0xE0, true): number of trailing bits set to 1 => 0 Ex: (0xF4, false): number of trailing bits set to 0 => 2 Ex: (0x87, true): number of trailing bits set to 1 => 3 static StringbinWithoutPrefix(String binStr)* Normalize a binary string to format "101010...." (No '0b' + bin string) if "0b" is present in input string, it is removed. -
-
Method Detail
-
decodeHex
static Array<byte> decodeHex(Array<char> data)
- Parameters:
data- (Eg.- Returns:
{10, 9, 12, ...}
-
encodeHex
static Array<char> encodeHex(Array<byte> data)
Encode a byte array into a char array.
- Parameters:
data- Data to be encoded (Eg.- Returns:
Encoded data as a char array (Eg. [ ' a ', ' 9 ', ' c ', ...])
-
encodeHex
static Array<char> encodeHex(Array<byte> data, boolean toLowerCase)
Encode a byte array into a char array.
- Parameters:
data- Data to be encoded (Eg.toLowerCase- True if result array needs to contains lowercase hexadecimal only.- Returns:
Encoded data as a char array (Eg. [ ' a ', ' 9 ', ' c ', ...])
-
encodeHexString
static String encodeHexString(Array<byte> data)
Converts a byte array into an hexadecimal string
- Parameters:
data- Array of byte to be converted to a hex string.- Returns:
an hexadecimal string: "a9c..."
-
convertTextToData
static Array<byte> convertTextToData(String text)
Convert String to byte []
- Parameters:
text- string to convert- Returns:
converted string
-
bytesToHexString
static String bytesToHexString(Array<byte> array, int bufSize)
Convert array of bytes into a hexadecimal string
- Parameters:
array- Array of byte to be converted to a hex stringbufSize- Size of bytes array.- Returns:
An hexadecimal string.
-
byteArrayToHexString
static String byteArrayToHexString(Array<byte> array, int size)
-
byteArrayToByteArray
static List<Byte> byteArrayToByteArray(Array<byte> data)
Convert a byte array to a List of Byte.
-
byteArrayToHexString
static String byteArrayToHexString(List<Byte> data)
Convert a List of Byte to a String.
-
byteArrayToHexString
static String byteArrayToHexString(Array<byte> a)
Convert array of bytes into a hexadecimal string
- Parameters:
a- Array of byte to be converted to a hex string- Returns:
An hexadecimal string.
-
byteArrayToBitString
static String byteArrayToBitString(Array<byte> a)
Convert array of bytes into a binary string of 0s and 1s
- Parameters:
a- Array of byte to be converted to a binary string- Returns:
a string representing the array in parameter
-
binToHexString
static String binToHexString(String binaries)
-
byteToHex
static String byteToHex(byte b)
Converts a byte into hexadecimal value
- Parameters:
b- Byte to convert- Returns:
String with a single hexadecimal value
-
byteToBitString
static String byteToBitString(byte n)
Converts a byte into binary string
- Parameters:
n- Byte to be converted.- Returns:
string of 0s and 1s characters representing the byte given as a parameter
-
hexToByte
static byte hexToByte(String s)
Converts a hexadecimal String value into a byte
- Parameters:
s- String with a single hexadecimal value to convert- Returns:
Byte
-
hexStringToByteArray
static Array<byte> hexStringToByteArray(String s)
Convert a String to a byte array
- Parameters:
s- String to be converted.- Returns:
byte array. Ex. [0xB6, 0x45, 0x92, ...]
-
hexStringToByteArrayList
@NonNull() static List<Byte> hexStringToByteArrayList(String hexData)
Convert a hex data hosted in a string to List of Byte
-
binaryStringToByteArray
static Array<byte> binaryStringToByteArray(String stream, boolean roundUpperByte)
Converts a string of 0s and 1s to a byte array.
- Parameters:
stream- the string to be convertedroundUpperByte- true to add an additional byte at the end if number of bits in stream is not multiple of 8- Returns:
a byte array of the string in parameter
-
binaryStringToByteArray
static Array<byte> binaryStringToByteArray(String stream)
Converts a string of 0s and 1s to a byte array. Do not add an additional byte at the end if number of bits in stream is not multiple of 8
- Parameters:
stream- the string to be converted- Returns:
a byte array of the string in parameter
-
byteListToByteArray
static Array<byte> byteListToByteArray(List<Byte> blist)
Helper method to convert a list of bytes to an array
- Parameters:
blist- A list of bytes to be converted.- Returns:
bytes array.
-
tryParseIntToHex
static String tryParseIntToHex(String s)
Convert a String representing an integer to Hexadecimal String with default value
- Parameters:
s- aStringcontaining theintrepresentation to be parsed- Returns:
hex string, "" if error
-
invertBitString
static String invertBitString(String data)
Invert the bits in binary string. For example String 000 should be inverted as 111 and 1101 as 0010.
- Parameters:
data- bit String to be inverted- Returns:
inverted string
-
containsOnlyHex
static boolean containsOnlyHex(String data)
Check if there is only hexadecimal digits (upper or lower case) in string.
- Parameters:
data- String to be checked- Returns:
true if String contains only [0-9A-Fa-f], false if any other character is found inside the string
-
containsOnlyBits
static boolean containsOnlyBits(String data)
Check if there is only 0/1 bits in binary string.
- Parameters:
data- bit String to be checked- Returns:
true if String contains only 0 or 1, false if any other character is found inside the string
-
countNumTrailingBitsInByte
static byte countNumTrailingBitsInByte(byte data, boolean polarity)
Return number of trailing bits of polarity set in byte data Ex: (0xE0, false): number of trailing bits set to 0 => 5 Ex: (0xE0, true): number of trailing bits set to 1 => 0 Ex: (0xF4, false): number of trailing bits set to 0 => 2 Ex: (0x87, true): number of trailing bits set to 1 => 3
- Returns:
number of trailing bits of polarity set in byte data
-
binWithoutPrefix
static String binWithoutPrefix(String binStr)
* Normalize a binary string to format "101010...." (No '0b' + bin string) if "0b" is present in input string, it is removed. Ex: "0b101010" -> "101010" Ex: "0B101010" -> "101010" Ex: "101010" -> "101010"
- Parameters:
binStr- binary String to normalize- Returns:
normalized binary String without "0b"
-
-
-
-