Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to use the function Math.log2() to get the base 2 logarithm of a number in JavaScript

1 Answer

0 votes
document.write("Math.log2(0) = " + Math.log2(0) + "<br />");
document.write("Math.log2(1) = " + Math.log2(1) + "<br />");
document.write("Math.log2(-1) = " + Math.log2(-1) + "<br />");
document.write("Math.log2(2) = " + Math.log2(2) + "<br />");
document.write("Math.log2(-2) = " + Math.log2(-2) + "<br />");
document.write("Math.log2(5) = " + Math.log2(5) + "<br />");
document.write("Math.log2(10) = " + Math.log2(10) + "<br />");
document.write("Math.log2(100) = " + Math.log2(100) + "<br />");
document.write("Math.log2(100000) = " + Math.log2(100000) + "<br />");
document.write("Math.log2(125) = " + Math.log2(125) + "<br />");
document.write("Math.log2(3) = " + Math.log2(3) + "<br />");
document.write("Math.log2(1024) = " + Math.log2(1024) + "<br />");

 
/*
run

Math.log2(0) = -Infinity
Math.log2(1) = 0
Math.log2(-1) = NaN
Math.log2(2) = 1
Math.log2(-2) = NaN
Math.log2(5) = 2.321928094887362
Math.log2(10) = 3.3219280948873626
Math.log2(100) = 6.643856189774725
Math.log2(100000) = 16.609640474436812
Math.log2(125) = 6.965784284662088
Math.log2(3) = 1.5849625007211563
Math.log2(1024) = 10
 
*/

 



answered Aug 4, 2016 by avibootz
...