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

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    Israel
    Posts
    174

    converting very big numbers from hex to dec

    am tring to conver the left number in the atached image to the on on the right but i recive overflow

    how can i slove this problem?
    thnaks i nadvance
    peleg

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

    Re: converting very big numbers from hex to dec

    Hi !
    I'm working on that. Hope to present you a solution soon. 100 decimal digits are enough ?

    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

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: converting very big numbers from hex to dec

    Here are some converterfunctions I have done for u, working up to 100 decimal digits
    Please test them. Hope that helps

    Jonny Poet
    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

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

    Re: converting very big numbers from hex to dec

    Unfortunately, that large of a number is too much for even a Long.

    Singles and Doubles can hold it, but because they use significant digits, the value of the number gets changed.

    With Single:
    Entered 144614369260322395
    Returned 144614366354866176

    With Double:
    Entered 144614369260322395
    Returned 144614369260322400

    My best suggestion would be to convert the hex into a String, and whenever you make comparisons, if you make any, just make sure the value it's being compared against gets put into CStr().
    Strings can perform direct comparisons with number strings perfectly as far as I can see, so "500" < "600" will return True, "455" <= "300" will return False, "400" <> "400" will return False, etc.
    Last edited by ChaosTheEternal; December 14th, 2005 at 08:51 AM.

  5. #5
    Join Date
    May 2004
    Location
    Israel
    Posts
    174

    Re: converting very big numbers from hex to dec

    i didnt execlly understamdnd you
    i ned oo convert 1 of them to the other format before i can compre!

    how will i do it?

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

    Re: converting very big numbers from hex to dec

    Make the comparisons as strings.

    Meaning, make both values being compared into Strings when you compare them, using the CStr() function if necessary.

  7. #7
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: converting very big numbers from hex to dec

    Quote Originally Posted by ChaosTheEternal
    ...
    My best suggestion would be to convert the hex into a String, and whenever you make comparisons, if you make any, just make sure the value it's being compared against gets put into CStr()....
    Yea, but I think he has to compare long decimals against hex values !! so he has to convert one of them before he can compare.
    So I did some converters.

    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

  8. #8
    Join Date
    Nov 2005
    Posts
    75

    Thumbs up Re: converting very big numbers from hex to dec

    Quote Originally Posted by JonnyPoet
    Yea, but I think he has to compare long decimals against hex values !! so he has to convert one of them before he can compare.
    So I did some converters.

    Jonny Poet
    Hey Jonny you are great... Thanks for help.

    P.S : I love this site.... I think the best coding site on the planet
    Last edited by jdavide; December 15th, 2005 at 01:13 AM.

  9. #9
    Join Date
    May 2004
    Location
    Israel
    Posts
    174

    Re: converting very big numbers from hex to dec

    hey Joney it worked!
    i need only 15 number length
    thnaks alot great day and great weekd end
    peleg

  10. #10
    Join Date
    May 2004
    Location
    Israel
    Posts
    174

    Re: converting very big numbers from hex to dec

    maybe u have the opposite:
    from dec to hex?

  11. #11
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: converting very big numbers from hex to dec

    Quote Originally Posted by ChaosTheEternal
    Strings can perform direct comparisons with number strings perfectly as far as I can see, so "500" < "600" will return True, "455" <= "300" will return False, "400" <> "400" will return False, etc.
    Just one note here ... the above examples work because they the same length.. if you try "9" < "10" you get false.. because in text digit 1 is compared to Digit 1 then digit 2, 3.....

    In this case use format to add in leading 0's

    Gremmy
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  12. #12
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: converting very big numbers from hex to dec

    Quote Originally Posted by GremlinSA
    Just one note here ... the above examples work because they the same length.. if you try "9" < "10" you get false.. because in text digit 1 is compared to Digit 1 then digit 2, 3.....

    In this case use format to add in leading 0's

    Gremmy
    Yes Gremmy you talked out of my soul. Yesterday I want to mention that, then I forgot. Today it was on my list to do that. You did

    BTW I just started to program the Long-Decimal-string to Binary and to Hex functions. Will be ready soon I hope.
    Last edited by JonnyPoet; December 15th, 2005 at 01:54 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

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

    Re: converting very big numbers from hex to dec

    For comparing strings, you could opt to check the lengths of them first, then the strings.
    Code:
    If Len(strOne) = Len(strTwo) Then
        If strOne > strTwo Then MsgBox "strOne is larger"
        If strOne < strTwo Then MsgBox "strTwo is larger"
        If strOne = strTwo Then MsgBox "strOne = strTwo"
    Else
        If Len(strOne) > Len(strTwo) Then MsgBox "strOne is larger"
        If Len(strOne) < Len(strTwo) Then MsgBox "strTwo is larger"
    End If

  14. #14
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    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

  15. #15
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    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

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