Package com.mku.convert
Class BitConverter
java.lang.Object
com.mku.convert.BitConverter
Converts from/to: byte arrays, integral values, and hex strings.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
toBytes
(long value, int length) Converts a long value to byte array.static byte[]
Convert a hex string to a byte array.static String
toHex
(byte[] data) Convert a byte array to a hex representation.static long
toLong
(byte[] bytes, int index, int length) Converts a byte array to a long value.
-
Constructor Details
-
BitConverter
public BitConverter()
-
-
Method Details
-
toBytes
public static byte[] toBytes(long value, int length) Converts a long value to byte array.- Parameters:
value
- The value to be converted.length
- The length of the byte array to be returned.- Returns:
- A byte array representation of the value.
-
toLong
public static long toLong(byte[] bytes, int index, int length) Converts a byte array to a long value. Little endian only.- Parameters:
bytes
- The byte array to be converted.index
- The starting index of the data in the array that will be converted.length
- The length of the data that will be converted.- Returns:
- The long value representation of the byte array.
-
toHex
Convert a byte array to a hex representation.- Parameters:
data
- The byte array to be converted.- Returns:
- The hex string representation.
-
toBytes
Convert a hex string to a byte array.- Parameters:
data
- The hex string to be converted.- Returns:
- The byte array converted from the string.
-