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. Managed C++/CLI
  4. Converting int to Hex String

Converting int to Hex String

Scheduled Pinned Locked Moved Managed C++/CLI
questionlearning
7 Posts 5 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.
  • M Offline
    M Offline
    MKlucher
    wrote on last edited by
    #1

    Anyone know how I would do this? I would think it's something like... int myNum = 7424; String * myNumAsHex = Convert::ToString(myNum, "X"); That doesn't work of course because I think you need to use the IFormatProvider class but I can't seem to use it correctly, any ideas?

    W V M 3 Replies Last reply
    0
    • M MKlucher

      Anyone know how I would do this? I would think it's something like... int myNum = 7424; String * myNumAsHex = Convert::ToString(myNum, "X"); That doesn't work of course because I think you need to use the IFormatProvider class but I can't seem to use it correctly, any ideas?

      W Offline
      W Offline
      wwwhb2000
      wrote on last edited by
      #2

      I think you can finish it as the following: int nNum = 7424; char szNum[20]; sprintf(szNum, "%x", nNum); Coding,I love it! MM,I Love it 2!!

      1 Reply Last reply
      0
      • M MKlucher

        Anyone know how I would do this? I would think it's something like... int myNum = 7424; String * myNumAsHex = Convert::ToString(myNum, "X"); That doesn't work of course because I think you need to use the IFormatProvider class but I can't seem to use it correctly, any ideas?

        V Offline
        V Offline
        VKatti
        wrote on last edited by
        #3

        itoa() with radix parameter set 16 will convert to HEX string See details of itoa()

        1 Reply Last reply
        0
        • M MKlucher

          Anyone know how I would do this? I would think it's something like... int myNum = 7424; String * myNumAsHex = Convert::ToString(myNum, "X"); That doesn't work of course because I think you need to use the IFormatProvider class but I can't seem to use it correctly, any ideas?

          M Offline
          M Offline
          MKlucher
          wrote on last edited by
          #4

          Thanks for your suggestions, is there a way to use the .NET framework to do this? Or must I use native code?

          W 1 Reply Last reply
          0
          • M MKlucher

            Thanks for your suggestions, is there a way to use the .NET framework to do this? Or must I use native code?

            W Offline
            W Offline
            wb
            wrote on last edited by
            #5

            are you sure, you CANT do it , the way you mentioned?? I did something like byte b = 44; string str = b.TosTring("X"); and it worked....

            M 1 Reply Last reply
            0
            • W wb

              are you sure, you CANT do it , the way you mentioned?? I did something like byte b = 44; string str = b.TosTring("X"); and it worked....

              M Offline
              M Offline
              MKlucher
              wrote on last edited by
              #6

              I figured it out, you need to use the Int32 class, AFAIK byte is a value type in MC++ so it couln't have the ToString associated with it. So it's Int32 test = 5432; String * testStr = test.ToString("X");

              S 1 Reply Last reply
              0
              • M MKlucher

                I figured it out, you need to use the Int32 class, AFAIK byte is a value type in MC++ so it couln't have the ToString associated with it. So it's Int32 test = 5432; String * testStr = test.ToString("X");

                S Offline
                S Offline
                S Senthil Kumar
                wrote on last edited by
                #7

                What? Value types derive from System.ValueType which in turn derives from System.Object, so they do have ToString() defined. Regards Senthil

                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