public class MathUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
bitCountToByteCount(int bitCount)
Computes the minimum number of bytes needed to cover
bitCount bits. |
static double |
bytesToDouble(byte[] bytes)
Inverse of
doubleToBytes(double). |
static byte[] |
doubleToBytes(double value)
Computes the big-endian byte array representation of the IEEE-754 8 byte
encoding of
value. |
static int |
gcd(int a,
int b)
Computes the greatest common divisor of two integers.
|
static byte[] |
nonNegativeLongToBigEndianBytes(int byteCount,
long value)
Produces the big-endian byte array representation of
value. |
static int |
numberOfLeadingZeros(byte b)
Unfortunately there is no Byte.numberOfLeadingZeros method.
|
static long |
unsignedBigEndianBytesToNonNegativeLong(byte[] bytes) |
public static int gcd(int a,
int b)
BigInteger.valueOf(a).gcd(BigInteger.valueOf(b))
.intValue(), but normally faster.public static byte[] nonNegativeLongToBigEndianBytes(int byteCount,
long value)
value. The
number must be non-negative and less than 1 << 8 * byteCount). In
other words, the big endian representation, without the bit sign, must fit
into byteCount bytes.byteCount - the fixed size wanted for the resultvalue - the numbervalue. The original number can be recovered via unsignedBigEndianBytesToNonNegativeLong(1, result).public static long unsignedBigEndianBytesToNonNegativeLong(byte[] bytes)
public static int bitCountToByteCount(int bitCount)
bitCount bits.public static byte[] doubleToBytes(double value)
value.public static double bytesToDouble(byte[] bytes)
doubleToBytes(double).public static int numberOfLeadingZeros(byte b)
Copyright © 2014. All Rights Reserved.