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
(int) Math.ceil((Math.log(n) / Math.log(2))
Of course this only works for positive integers.