Package com.mku.convert
Class BitConverter
- java.lang.Object
-
- com.mku.convert.BitConverter
-
public class BitConverter extends java.lang.ObjectConverts from/to: byte arrays, integral values, and hex strings.
-
-
Constructor Summary
Constructors Constructor Description BitConverter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]toBytes(long value, int length)Converts a long value to byte array.static byte[]toBytes(java.lang.String data)Convert a hex string to a byte array.static java.lang.StringtoHex(byte[] data)Convert a byte array to a hex representation.static longtoLong(byte[] bytes, int index, int length)Converts a byte array to a long value.
-
-
-
Method Detail
-
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
public static java.lang.String toHex(byte[] data)
Convert a byte array to a hex representation.- Parameters:
data- The byte array to be converted.- Returns:
- The hex string representation.
-
toBytes
public static byte[] toBytes(java.lang.String data)
Convert a hex string to a byte array.- Parameters:
data- The hex string to be converted.- Returns:
- The byte array converted from the string.
-
-