log2()

log2(x) returns logarithm of x with base 2
import math
print(math.log2(2))  # 1.0
print(math.log2(4))  # 2.0
print(math.log2(5))  # 2.321928094887362
Using negative number
For any value less than or equal to 0 , we will get ValueError
import math
print(math.log2(-2))
Above code will generate error.

Use Case: Data Size Calculation: To calculate how many bits are needed to store a number:
print(math.log2(1024) + 1)  # Output: 11.0
log modf()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer