converting very big numbers from hex to dec - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21

Thread: converting very big numbers from hex to dec

  1. #16
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: converting very big numbers from hex to dec

    Tratatata...............

    Here it is, have fun.

    A compare Function is added too!
    Attached Files Attached Files
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  2. #17
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: converting very big numbers from hex to dec

    Quote Originally Posted by ChaosTheEternal
    Code:
    ...
    	If Len(strOne) > Len(strTwo) Then MsgBox "strOne is larger"
    	If Len(strOne) < Len(strTwo) Then MsgBox "strTwo is larger"
    ...
    Hey Chaos ! Try compare string "00005" with "70" and you will see its not working like that in mathematical strings, because in that case "00005" is longer but value is less ! But dont worry. it was basically your idea of comparing strings that I used to figure out the functions in my zipfile.

    Jonny Poet
    Last edited by JonnyPoet; December 15th, 2005 at 04:42 PM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #18
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: converting very big numbers from hex to dec

    If you import a number into a String (such as via CStr() or some custom method), there would be no leading zeroes. So it would work.

    My intent for that was on that line of thinking.

    Since you can't even try:
    Code:
    Debug.Print CStr(00005)
    Due to VB automatically getting rid of the leading zeroes, I tried:
    Code:
    Private Sub Command1_Click()
        Debug.Print CStr(CLng(Text1.Text))
    End Sub
    I entered various numbers with a lot of trailing zeroes (like 00000006579) and only got the necessary value output (i.e. "6579", instead of "00000006579").

  4. #19
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: converting very big numbers from hex to dec

    Quote Originally Posted by ChaosTheEternal
    If you import a number into a String (such as via CStr() or some custom method), there would be no leading zeroes. So it would work.
    My intent for that was on that line of thinking.
    Since you can't even try:
    Code:
    Debug.Print CStr(00005)
    Due to VB automatically getting rid of the leading zeroes, I tried:
    Code:
    Private Sub Command1_Click()
    Debug.Print CStr(CLng(Text1.Text))
    End Sub
    I entered various numbers with a lot of trailing zeroes (like 00000006579) and only got the necessary value output (i.e. "6579", instead of "00000006579").
    I understand what you are talking about but think - you have long strings of numbers to transcode so you cannot use CLng() you cannot even change the string into a value you have to add or subtract digit by digit and in that way you may get some leading zeros for example if you have
    "12378934567" - "12324512455" or something like that you get "00054422112" and if you dont want to have trailing zeros you have to cut them away digit by digit from left to right until the digitvalue is > then 0.

    If you try to do such a convert function you will see it will never work CStr(CLng(Text1.Text)) when Text1.Text exceeds the maxvalues of a long. Additional : You cannot compare a Hex-Value -string with a Decimal-Value-string that leads to nothing,so you have to transcode one of them, you see ?

    Jonny Poet
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  5. #20
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: converting very big numbers from hex to dec

    Firstly, I was using CStr(CLng()) as an example that trying to put a number in with leading zeroes removes those zeroes automatically, as long as it is actually a number somewhere in there. Not as what you would actually do.

    Secondly, it's comparisons. No addition or subtraction was required for his issue.

    I know if you were to put the numbers in Strings and had to perform some mathematics on them, you would need to split up the whole number and do digit by digit comparisons, then piece the number to what it would really equal, and then optionally put it back into the String.

    Doing anything beyond addition or subtraction would be a bit more difficult. Multiplication would be a lot easier than division (though for division, I would guess a lot of Modulus division would be involved).

    And it's not hard to remove leading zeros from a String if you would manage to get them.
    Code:
    Do Until Left(strNumber, 1) <> "0"
        strNumber = Right(strNumber, Len(strNumber) - 1)
    Loop

  6. #21
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,537

    Re: converting very big numbers from hex to dec

    Quote Originally Posted by ChaosTheEternal
    ...
    Code:
    Do Until Left(strNumber, 1) <> "0"
    strNumber = Right(strNumber, Len(strNumber) - 1)
    Loop
    That methode is correct. So you have to add this in the beginning of your compare function and it will do its job.

    The best to understand the problem is, if you look into the working code I did. Then you will see what I'm talking about. Basically is.. You cannot directly compare a string which holds a hexadecimal with a string which holds a decade value, for finding out which number is bigger. You need to transform one of them before you compare. I think you agree on that.

    For transformation I needed addition, subtraction and exponents-of-two and comparing-values-in stringform functions, all having the values in form of strings. And for comparing you can do a) removing trailing zeros or b) adding trailng zeros to get same string length before comparing, because you dont know what you will get as a result of transformation process. The result may or may not have some trailing zeros in the resultstring.

    And the basic idea how to get it done, for really big values was to calculate all during holding the values as a string. And this simple idea, which I followed my buddy, was yours and thats what counts.

    Jonny Poet
    PS.: Really Big things are always simple.
    Last edited by JonnyPoet; December 16th, 2005 at 03:37 PM. Reason: typos corrected
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Page 2 of 2 FirstFirst 12

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center