![]() |
how do you find number of digits of a 2^n number?
hi all,
I found this program yesterday and i was thinking about how to tell how many digits are in a 2^n number if i knew n. I made a Microsoft Excel spreadsheet and calculated out about 40 sequences, and eventually found a pattern relating the n's that end in 0 (multiples of 10). my pattern was ((3/10)*n) + 1. for example, using 0 for n, the result (number of digits in 2^n) is 1, as it should be. using 10, 20, 30, and 40 for n, i get 4, 7, 10, 13 respectively. i checked the actual digits by doing the math on the calculator and counting digits, and the pattern works. i found this page [url]http://www.utm.edu/research/primes/mersenne/index.html[/url] which showed a table of known mersenne primes. i tested my equation on the table, and got good results until n=1279. according to the chart, 2^n should have 386 digits. however, when i plugged it into my equation, i came up with 384 digits. each n after that also gave incorrect answers, and they get continually worse. for example, the 40th mersenne prime, 2^20996011 -1 has 6,320,430 digits according to the chart, but only 6,298,804 digits according to my equation (i used n=20996010 to get the answer, because i found a pattern that shows that after a multiple of 10, the next 3 have the same amount of digits, followed by 3 with 1 more digit, another 3 with 2 more digits, and then the next multiple of 10 is reached). So, i was wondering how you guys got the number of digits in a 2^n number, and why my equation and the "known" digits are so far off. thanks in advance, michael p.s. if you don't understand what i wrote, say so and i'll try to clarify. |
floor(log 2 * n) + 1
Where log is base 10. |
There are ceiling (n * log10(2)) digits. The base 10 log of 2 is .30103
|
ah, that makes sense. now i see why mine are so close at the beginning and then so far off later on.
but then, another quick question--what do floor and ceiling mean? |
floor is round down. ceiling is round up.
|
ah, got it. thanks
|
Are floor and ceiling terms simply the same thing as the boundaries of the logarithmic functions?
|
They're just "functions".
floor refers to the integer that is closest to a number without being higher. ceiling refers to the integer that is closest to a number without being lower. They're just fancy names for rounding up and rounding down. |
I don't know about other languages.. but I know that I use floor and ceiling a lot in both excel and matlab. Both floor and ceiling are acual "functions" in both programs. However, I haven't actually ever seen floor or ceiling written in any maths textbooks as far as I can remember... I could be wrong though.
|
[QUOTE=dave_0273]I don't know about other languages.. but I know that I use floor and ceiling a lot in both excel and matlab. Both floor and ceiling are acual "functions" in both programs. However, I haven't actually ever seen floor or ceiling written in any maths textbooks as far as I can remember... I could be wrong though.[/QUOTE]
In printed text the floor and ceiling functions are generally written as partial square brackets. I don't know that I can include the characters here, but they look something like this: floor(x) is represented by |_ x _| and ceiling(x) has the horizontal lines at the top. Paul |
See
[url="http://mathworld.wolfram.com/FloorFunction.html"]http://mathworld.wolfram.com/FloorFunction.html[/url] and [url="http://mathworld.wolfram.com/CeilingFunction.html"]http://mathworld.wolfram.com/CeilingFunction.html[/url] for clear examples and fuller explanation. |
| All times are UTC. The time now is 18:06. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.