logarithm base 2 calculation in java

By default java provides base 10 using In build Math class


Base 10 log


Math.log(input) ;


Base 2 log


Math.log(input) / Math.log(2);


This methods will return values in double so if you need integer 

int zeros=(int) (Math.log(input)/ Math.log(2));






No comments:

^ Top