Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Problem Converting Hex to Decimal

Problem Converting Hex to Decimal

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpcsharptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VikashGohil
    wrote on last edited by
    #1

    Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.

    L E V 4 Replies Last reply
    0
    • V VikashGohil

      Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Well 0x8CF1152C has the sign bit set (assuming 32bit signed int), and therefore it's negative (if you treat it as singed int), but I don't know anything about VB or CDec so I don't really know what's going on here

      1 Reply Last reply
      0
      • V VikashGohil

        Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        In VB6 an Int is 16 bits and not 32 bits. This is the cause of many, many cross language problems involving VB6.

        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

        1 Reply Last reply
        0
        • V VikashGohil

          Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Harold has the right answer, the conversion fails because one is signed, and the other isn't. You can do this conversion in VB6 using this code;

          'Helperfunctions;
          Private Const OFFSET_4 = 4294967296#

          Function LongToUnsigned(Value As Long) As Double
          If Value < 0 Then
          LongToUnsigned = Value + OFFSET_4
          Else
          LongToUnsigned = Value
          End If
          End Function

          ' Actual conversion;
          Dim longNumber As Long
          longNumber = &H8CF1152C
          unsignedNumber = LongToUnsigned(longNumber)

          MsgBox (CStr(unsignedNumber))

          That should do the trick :)

          I are Troll :suss:

          1 Reply Last reply
          0
          • V VikashGohil

            Hello, this is Vikash. I am facing a problem related to Conversion of Hex String into Decimal Value. The problem does not occur when the code is run in VB.net 2005. But the same Code when run in VB6.0 gives a negative value. This is the Code in VB.net : dim C as string C = CDec("&H" & "8CF1152C") The Value of C in this case is "2364609836" The same Code in VB6.0 gives C value as "-1930357460" Could anyone tell me why this is happening or how to solve this problem? Any help would be highly appreciated. Thanks In Advance.

            V Offline
            V Offline
            VikashGohil
            wrote on last edited by
            #5

            Thanks everyone for the reply. Solution given by Eddy worked. Now I am getting the same output as in VB.net. Thanks once again.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups