In code how does one count the digits of a very large number?
The number has over 50,000 digits, and is of the form k*2^n -1.
With(k<2^n)
Thanks in advance!:p
Printable View
In code how does one count the digits of a very large number?
The number has over 50,000 digits, and is of the form k*2^n -1.
With(k<2^n)
Thanks in advance!:p
This is a start, crude but it may help a little.
All you need is a textbox and button. Im not sure but an integer has a limit, you may have to use long or something else but check on it because Im not sure.
Code:Private Sub Command1_Click()
Dim number As String
Dim count As Integer
number = Text1.Text
count = Len(number)
MsgBox count
End Sub
dedub
Thanks for the Text idea.
I was thinking of log (k*2^n-1),
but one still has to write (k*2^n-1).
I believe integers and longs both have limits, so
I thought maybe by knowing the exponent, and multiplier
it would be easier to calculate the number of digits.
:D
This is a statistical function of my free software to find large prime numbers. An older version is available here: http://15k.org/rma/
The new version 1.7 rocks! but is still in progress...
The answer is to break it up, duh....
floor(n*log(2)/log(10)) + log(k) + 1
Thanks to Chris Caldwell for some help with base 2.
:wave:
Static Function Log10(k)
Log10 = log(txtInputk) / log(10)
End Function
Private Sub cmdlog_Click()
Dim loginput As Long
Dim logoutput As Variant
Dim strlog As String
Dim n As Long
Dim z As Long
n = txtInputn
z = txtInputn * 0.301029995 ' or log(2)
loginput = txtInputk
logoutput = txtlog
txtlog = Log10(k)
strlog = txtlog
strlog = Left$(strlog, 2)
txtlog = strlog + 1
txtlog = txtlog + z
End Sub
In the above code, different bases can be used by replacing base 2.:blush: :D