How to write log base(2) in c/c++ December 27, 2022 by Tarik Simple math: log2 (x) = logy (x) / logy (2) where y can be anything, which for standard log functions is either 10 or e.