public class Utils extends Object
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
bigIntegerToBytes(BigInteger b,
int numBytes)
The regular
BigInteger.toByteArray() includes the sign bit of the number and
might result in an extra byte addition. |
static byte[] |
longToBytes(long value) |
static String |
toAddressFromPublicKey(String publicKey) |
static byte[] |
toByteArray(String s) |
static String |
toHexString(byte[] bytes) |
public static byte[] bigIntegerToBytes(BigInteger b, int numBytes)
The regular BigInteger.toByteArray() includes the sign bit of the number and
might result in an extra byte addition. This method removes this extra byte.
Assuming only positive numbers, it's possible to discriminate if an extra byte is added by checking if the first element of the array is 0 (0000_0000). Due to the minimal representation provided by BigInteger, it means that the bit sign is the least significant bit 0000_0000 . Otherwise the representation is not minimal. For example, if the sign bit is 0000_0000, then the representation is not minimal due to the rightmost zero.
b - the integer to format into a byte arraynumBytes - the desired size of the resulting byte arraypublic static String toHexString(byte[] bytes)
bytes - public static byte[] toByteArray(String s)
s - public static byte[] longToBytes(long value)
value - Copyright © 2019. All rights reserved.