For a given unsigned int
value, I tried following method for the number of bits for storing given value.
// Returns the number of required bits for (storing) specified unsigned value.
static int size(final int value) {
if (value < 0) {
throw new IllegalArgumentException("value(" + value + ") is negative");
}
return (int) Math.ceil(Math.log10(value) / Math.log10(2));
}
And here comes what I got.
size for 1310394095: 31 (RANDOM)
size for 1: 0 (1; Not Good; should be 1)
size_NotNegative_Zero() is @Disabled (0; ERROR; Expecting actual: -2147483648 ...)
size for 2147483647: 31 (Integer.MAX_VALUE)
The 31
for Integer.MAX_VALUE
seems OK.
How can I fix this?