If you have the binary number 10110 how can I get it to return 5? e.g a number that tells how many bits are used? There are some likewise examples listed below:
Unfortunately there is no Integer.bitLength() method that would give you the answer directly.
An analogous method exists for BigInteger, so you could use that one:
BigInteger.valueOf(value).bitLength()
Constructing the BigInteger object will make it somewhat less efficient, but that will only matter if you do it many millions of times.