Package org.uncommons.maths.binary
Class BinaryUtils
- java.lang.Object
-
- org.uncommons.maths.binary.BinaryUtils
-
public final class BinaryUtils extends java.lang.ObjectUtility methods for working with binary and hex data.
-
-
Field Summary
Fields Modifier and Type Field Description private static intBITWISE_BYTE_TO_INTprivate static char[]HEX_CHARS
-
Constructor Summary
Constructors Modifier Constructor Description privateBinaryUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringconvertBytesToHexString(byte[] data)Converts an array of bytes in to a String of hexadecimal characters (0 - F).static intconvertBytesToInt(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 longconvertBytesToLong(byte[] bytes, int offset)Utility method to convert an array of bytes into a long.static BitStringconvertDoubleToFixedPointBits(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[]convertHexStringToBytes(java.lang.String hex)Converts a hexadecimal String (such as one generated by theconvertBytesToHexString(byte[])method) into an array of bytes.
-
-
-
Field Detail
-
BITWISE_BYTE_TO_INT
private static final int BITWISE_BYTE_TO_INT
- See Also:
- Constant Field Values
-
HEX_CHARS
private static final char[] HEX_CHARS
-
-
Method Detail
-
convertBytesToHexString
public static java.lang.String convertBytesToHexString(byte[] data)
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
public static byte[] convertHexStringToBytes(java.lang.String hex)
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
public 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).- Parameters:
value- The value to convert (must be between zero and one).- Returns:
- A bit string representing the value in fixed-point format.
-
-