This is probably pretty basic, but to save me an hour or so of grief can anyone tell me how you can work out the number of bits required to represent a given positive intege
For non-negative values, probably the most direct answer is:
java.math.BigDecimal.valueOf(value).bitLength()
(For negative numbers it will give the bit length of one less than the absolute value, rather than infinity you'd expect from two's complement notation.)