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. how to convert hex to int

how to convert hex to int

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
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.
  • E Offline
    E Offline
    Electronic75
    wrote on last edited by
    #1

    Hello board,is there a function to convert for example "0xFF" or "0F" to their corresponding int 255,16 ? I couldn't find a function like atoi so how should I do that? thanks.

    D C 2 Replies Last reply
    0
    • E Electronic75

      Hello board,is there a function to convert for example "0xFF" or "0F" to their corresponding int 255,16 ? I couldn't find a function like atoi so how should I do that? thanks.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Have you considered strtol()?

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      E 1 Reply Last reply
      0
      • D David Crow

        Have you considered strtol()?

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        E Offline
        E Offline
        Electronic75
        wrote on last edited by
        #3

        thanks a lot david, you solved the problem.

        1 Reply Last reply
        0
        • E Electronic75

          Hello board,is there a function to convert for example "0xFF" or "0F" to their corresponding int 255,16 ? I couldn't find a function like atoi so how should I do that? thanks.

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          strtol [^] function, called with base=16, does the magic, for instance:

          char * szHex = "0F";
          char * szStop;
          int i;
          i = strtol(szHex, &szStop, 16);
          printf("%s hex = %d dec\n", szHex, i);

          Please note the output of the program:

          0F hex = 15 dec

          :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          E 1 Reply Last reply
          0
          • C CPallini

            strtol [^] function, called with base=16, does the magic, for instance:

            char * szHex = "0F";
            char * szStop;
            int i;
            i = strtol(szHex, &szStop, 16);
            printf("%s hex = %d dec\n", szHex, i);

            Please note the output of the program:

            0F hex = 15 dec

            :-D

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            [my articles]

            E Offline
            E Offline
            Electronic75
            wrote on last edited by
            #5

            thanks alot pallini!

            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