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:
I think the rounded-up log_2 of that number will give you what you need.
Something like:
return (int)(Math.log(value) / Math.log(2)) + 1;