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. Read Hexidecimal

Read Hexidecimal

Scheduled Pinned Locked Moved C / C++ / MFC
jsonquestion
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.
  • P Offline
    P Offline
    Paul M Watt
    wrote on last edited by
    #1

    Are there any standard functions, either in the c libary or in windows, that can be used to read a hexidecimal number from a string similar to atoi?


    Build a man a fire, and he will be warm for a day
    Light a man on fire, and he will be warm for the rest of his life!

    J PJ ArendsP 2 Replies Last reply
    0
    • P Paul M Watt

      Are there any standard functions, either in the c libary or in windows, that can be used to read a hexidecimal number from a string similar to atoi?


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      J Offline
      J Offline
      Jon Sagara
      wrote on last edited by
      #2

      sscanf(), if you have a formatted string. For example:

      #include <iostream>
      #include <cstdio>

      using namespace std;

      int main()
      {
      string str = "0x1F";
      int hex = 0;
      sscanf(str.c_str(), "%X", &hex);
      cout << "Hex value: " << hex << endl;
      return 0;
      }

      Jon Sagara Working with a database is iterative, like sex, but painful instead of pleasurable. -- Marc Clifton[^]

      P 1 Reply Last reply
      0
      • P Paul M Watt

        Are there any standard functions, either in the c libary or in windows, that can be used to read a hexidecimal number from a string similar to atoi?


        Build a man a fire, and he will be warm for a day
        Light a man on fire, and he will be warm for the rest of his life!

        PJ ArendsP Offline
        PJ ArendsP Offline
        PJ Arends
        wrote on last edited by
        #3

        strtol() or strtoul()


        CPUA 0x5041 Sonork 100.11743 Chicken Little "So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies Within you lies the power for good - Use it!

        Within you lies the power for good; Use it!

        P 1 Reply Last reply
        0
        • J Jon Sagara

          sscanf(), if you have a formatted string. For example:

          #include <iostream>
          #include <cstdio>

          using namespace std;

          int main()
          {
          string str = "0x1F";
          int hex = 0;
          sscanf(str.c_str(), "%X", &hex);
          cout << "Hex value: " << hex << endl;
          return 0;
          }

          Jon Sagara Working with a database is iterative, like sex, but painful instead of pleasurable. -- Marc Clifton[^]

          P Offline
          P Offline
          Paul M Watt
          wrote on last edited by
          #4

          I saw this before, but for some reason it did not seem that it worked that way to me. Thanks


          Build a man a fire, and he will be warm for a day
          Light a man on fire, and he will be warm for the rest of his life!

          1 Reply Last reply
          0
          • PJ ArendsP PJ Arends

            strtol() or strtoul()


            CPUA 0x5041 Sonork 100.11743 Chicken Little "So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies Within you lies the power for good - Use it!

            P Offline
            P Offline
            Paul M Watt
            wrote on last edited by
            #5

            Thanks, this is exactly what I was looking for.


            Build a man a fire, and he will be warm for a day
            Light a man on fire, and he will be warm for the rest of his life!

            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