CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Rma

  1. #1
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Thumbs up Rma

    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!

  2. #2
    Join Date
    Dec 2002
    Location
    NC
    Posts
    125
    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
    R.L.T.W. A+, NET+, CCNA

    doin' my best

  3. #3
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Exclamation longs integers

    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.



    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...

  4. #4
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    solution

    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.

    Last edited by TT(n); June 26th, 2004 at 08:03 PM.

  5. #5
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Thumbs up Digit counter for bases

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured