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. C / C++ / MFC
  4. CString to HEX

CString to HEX

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 Posts 4 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.
  • B Offline
    B Offline
    Benjamin Bruno
    wrote on last edited by
    #1

    Hi How to convert a CString value to HEX? eg: CString strHex = "0008103e"; to HEX value = 0x0008103e please help Thanks

    C R A 3 Replies Last reply
    0
    • B Benjamin Bruno

      Hi How to convert a CString value to HEX? eg: CString strHex = "0008103e"; to HEX value = 0x0008103e please help Thanks

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      An hex value doesn't exist, what you want probably is to convert a string representing an integer in hexadecimal notation to an integer. For this you can use strtol[^] function.

      Cédric Moonen Software developer
      Charting control [v3.0] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • B Benjamin Bruno

        Hi How to convert a CString value to HEX? eg: CString strHex = "0008103e"; to HEX value = 0x0008103e please help Thanks

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        Benjamin Bruno wrote:

        How to convert a CString value to HEX? eg: CString strHex = "0008103e"; to HEX value = 0x0008103e

        What Cedric said.

        ULONG nVal;
        CString str = _T("0x4335");
        nVal = _tcstol(str, NULL, 0);

        It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.

        1 Reply Last reply
        0
        • B Benjamin Bruno

          Hi How to convert a CString value to HEX? eg: CString strHex = "0008103e"; to HEX value = 0x0008103e please help Thanks

          A Offline
          A Offline
          Alain Rist
          wrote on last edited by
          #4

          You got excellent C answers. In C++ use the facilities of the Standard C++ Library:

          #include <sstream>
          int GetIntFromHexString(const char* HexString)
          {
          int val;
          std::istringstream(HexString) >> std::hex >> val;
          return val;
          }

          cheers, AR

          When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)

          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