Package net.osslabz.evm.abi.util
Class ByteUtil
java.lang.Object
net.osslabz.evm.abi.util.ByteUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]bigIntegerToBytes(BigInteger value) Omitting sign indication byte.static byte[]bigIntegerToBytes(BigInteger b, int numBytes) The regularBigInteger.toByteArray()method isn't quite what we often need: it appends a leading zero to indicate that the number is positive and may need padding.static byte[]bigIntegerToBytesSigned(BigInteger b, int numBytes) static BigIntegerbytesToBigInteger(byte[] bb) static byte[]merge(byte[]... arrays) static StringtoHexString(byte[] data) Convert a byte-array into a hex String.
Works similar toHex.toHexString(byte[])but allows fornull
-
Constructor Details
-
ByteUtil
public ByteUtil()
-
-
Method Details
-
toHexString
Convert a byte-array into a hex String.
Works similar toHex.toHexString(byte[])but allows fornull- Parameters:
data- - byte-array to convert to a hex-string- Returns:
- hex representation of the data.
Returns an empty String if the input isnull - See Also:
-
Hex.toHexString(byte[])
-
bytesToBigInteger
-
bigIntegerToBytes
Omitting sign indication byte.
Instead of org.spongycastle.util.BigIntegers#asUnsignedByteArray(BigInteger
we use this custom method to avoid an empty array in case of BigInteger.ZERO- Parameters:
value- - any big integer number. Anull-value will returnnull- Returns:
- A byte array without a leading zero byte if present in the signed encoding. BigInteger.ZERO will return an array with length 1 and byte-value 0.
-
bigIntegerToBytes
The regularBigInteger.toByteArray()method isn't quite what we often need: it appends a leading zero to indicate that the number is positive and may need padding.- Parameters:
b- the integer to format into a byte arraynumBytes- the desired size of the resulting byte array- Returns:
- numBytes byte long array.
-
bigIntegerToBytesSigned
-
merge
public static byte[] merge(byte[]... arrays) - Parameters:
arrays- - arrays to merge- Returns:
- - merged array
-