 ## [Math] Binary logarithm, part III

Inline:

For example, a license key/code contains 40 Latin characters (A..Z). How many possible license codes can be? (Python)

import math

total=26**40

total
397131118389635994560666234198316439032157304558637285376


How many bits/bytes a license key/code can contain?

math.log(total,2)
188.0175887256437

math.log(total,2)/8
23.50219859070546


So a license code can contain 189 bits or 24 bytes.

But we employ here Python's capability of bignums. Can we calculate this using real/floating numbers? Like, in pure C?

Let's use the fact that $$log_{26}(total) = 40$$. To convert a logarithm of a number in base X to logarithm in base Y, multiply it by $$\frac{log(X)}{log(Y)}$$.

math.log(total,26)
40.0

math.log(26)/math.log(2)
4.700439718141093

40*(math.log(26)/math.log(2))
188.0175887256437


math.log(x) is natural logarith, but any base will work during 'coversion':

40*(math.log(26,123)/math.log(2,123))
188.0175887256437


###### (the post first published at 20230220.) Yes, I know about these lousy Disqus ads. Please use adblocker. I would consider to subscribe to 'pro' version of Disqus if the signal/noise ratio in comments would be good enough.