Package org.uncommons.maths.binary
Class BinaryUtils
java.lang.Object
org.uncommons.maths.binary.BinaryUtils
Utility methods for working with binary and hex data.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final char[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
convertBytesToHexString
(byte[] data) Converts an array of bytes in to a String of hexadecimal characters (0 - F).static int
convertBytesToInt
(byte[] bytes, int offset) Take four bytes from the specified position in the specified block and convert them into a 32-bit int, using the big-endian convention.static int[]
convertBytesToInts
(byte[] bytes) Convert an array of bytes into an array of ints.static long
convertBytesToLong
(byte[] bytes, int offset) Utility method to convert an array of bytes into a long.static BitString
convertDoubleToFixedPointBits
(double value) Converts a floating point value in the range 0 - 1 into a fixed point bit string (where the most significant bit has a value of 0.5).static byte[]
Converts a hexadecimal String (such as one generated by theconvertBytesToHexString(byte[])
method) into an array of bytes.
-
Field Details
-
BITWISE_BYTE_TO_INT
private static final int BITWISE_BYTE_TO_INT- See Also:
-
HEX_CHARS
private static final char[] HEX_CHARS
-
-
Constructor Details
-
BinaryUtils
private BinaryUtils()
-
-
Method Details
-
convertBytesToHexString
Converts an array of bytes in to a String of hexadecimal characters (0 - F).- Parameters:
data
- An array of bytes to convert to a String.- Returns:
- A hexadecimal String representation of the data.
-
convertHexStringToBytes
Converts a hexadecimal String (such as one generated by theconvertBytesToHexString(byte[])
method) into an array of bytes.- Parameters:
hex
- The hexadecimal String to be converted into an array of bytes.- Returns:
- An array of bytes that.
-
convertBytesToInt
public static int convertBytesToInt(byte[] bytes, int offset) Take four bytes from the specified position in the specified block and convert them into a 32-bit int, using the big-endian convention.- Parameters:
bytes
- The data to read from.offset
- The position to start reading the 4-byte int from.- Returns:
- The 32-bit integer represented by the four bytes.
-
convertBytesToInts
public static int[] convertBytesToInts(byte[] bytes) Convert an array of bytes into an array of ints. 4 bytes from the input data map to a single int in the output data.- Parameters:
bytes
- The data to read from.- Returns:
- An array of 32-bit integers constructed from the data.
- Since:
- 1.1
-
convertBytesToLong
public static long convertBytesToLong(byte[] bytes, int offset) Utility method to convert an array of bytes into a long. Byte ordered is assumed to be big-endian.- Parameters:
bytes
- The data to read from.offset
- The position to start reading the 8-byte long from.- Returns:
- The 64-bit integer represented by the eight bytes.
- Since:
- 1.1
-
convertDoubleToFixedPointBits
Converts a floating point value in the range 0 - 1 into a fixed point bit string (where the most significant bit has a value of 0.5).- Parameters:
value
- The value to convert (must be between zero and one).- Returns:
- A bit string representing the value in fixed-point format.
-