How can I find the log 2 base of a double variable?

Michael Pnrs :

I'm trying to calculate the log 2 base of some double form numbers but it seems that there isn't a standard method from a libraly for that.

I tried out this code,error occurs though.

        double entropy=0;
        for(int i=0; i<26;i++){
            entropy+=-possibilityCounter[i]*log2(possibilityCounter[i]);
        }

NOTE: possibilityCounter table is full of double variables e.g 0.00133536

Any suggestion?

b.GHILAS :

You can calculate the log base 2 from the natural log like this

public double log2(double v) {
    return Math.log(v) / Math.log(2);
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=418403&siteId=1