- java.lang.Object
-
- com.github.f4b6a3.uuid.util.internal.ByteUtil
-
public final class ByteUtil extends Object
Utility class that contains many static methods for byte handling.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]fromInts(int[] ints)Converts an array of integers into an array of bytes.static StringtoHexadecimal(byte[] bytes)Get a hexadecimal string from given array of bytes.static int[]toInts(byte[] bytes)Converts an array of bytes into an array of integers.static longtoNumber(byte[] bytes)Get a number from a given array of bytes.static longtoNumber(byte[] bytes, int start, int end)Get a number from a given array of bytes.
-
-
-
Method Detail
-
toNumber
public static long toNumber(byte[] bytes)
Get a number from a given array of bytes.- Parameters:
bytes- a byte array- Returns:
- a long
-
toNumber
public static long toNumber(byte[] bytes, int start, int end)Get a number from a given array of bytes.- Parameters:
bytes- a byte arraystart- first byte of the arrayend- last byte of the array (exclusive)- Returns:
- a long
-
toHexadecimal
public static String toHexadecimal(byte[] bytes)
Get a hexadecimal string from given array of bytes.- Parameters:
bytes- byte array- Returns:
- a string
-
toInts
public static int[] toInts(byte[] bytes)
Converts an array of bytes into an array of integers. Each integer is formed by combining 4 bytes from the input array. This method assumes that the input byte array is at least 16 bytes long. The conversion is done by treating each set of 4 bytes as a single integer, with the first byte being the most significant.- Parameters:
bytes- An array of bytes to be converted into integers. This array should be at least 16 bytes long.- Returns:
- An array of 4 integers, where each integer is formed by combining 4 bytes from the input array.
-
fromInts
public static byte[] fromInts(int[] ints)
Converts an array of integers into an array of bytes. Each integer is decomposed into 4 bytes, with the most significant byte being placed first. This method produces a byte array of length 16, assuming the input array contains exactly 4 integers. The conversion is performed by shifting and masking operations to extract each byte from the integers.- Parameters:
ints- An array of integers to be converted into bytes. This array should contain exactly 4 integers.- Returns:
- A byte array of length 16, where each group of 4 bytes represents one of the integers from the input array.
-
-