How to write log base(2) in c/c++
Simple math:
log2 (x) = logy (x) / logy (2)
where y can be anything, which for standard log functions is either 10 or e.
C99 has log2
(as well as log2f
and log2l
for float and long double).
If you're looking for an integral result, you can just determine the highest bit set in the value and return its position.