java - The Inverse of a bit-shift to the left in the format 1 << n -


let's have following bit masks:

1 << 1, // 2 1 << 2, // 4  1 << 3, // 8  1 << 4, // 16  1 << 5, // 32  1 << 6  // 64 

i 'inverse'.

this job:

void foo(int n) {   int c = 1;   while (n/2 >= 2) {     n /= 2;       c++;;   }   println(c); } 

for example, 1 << 4 resulted in 16. if run foo(16) prints 4. however, feel done lot simpler, can't figure out how.

is possible?

biginteger has many useful methods - including getlowestsetbit(). fast can possibly done.

public void test() {     system.out.println(biginteger.valueof(16).getlowestsetbit()); } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -