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. converting Hex to int

converting Hex to int

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorialquestion
15 Posts 7 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.
  • T toxcct

    this doesn't mean anything to convert from hexadecimal to int... hexadecimal IS an integer, but it only differs from the graphical representation... if you have 32 apples, it is the same as having 0x20 apples... what you certainly mean however is reading hexadecimal characters from a string (but that is important to know if it is a string or not) into ints... if so, sscanf() is done your you. otherwise, give more details about what you really have, and what you really want... cheers,

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

    v2.0 wrote:

    if you have 32 apples, it is the same as having 0x20 apples...

    It reminds me of another discussion[^] :laugh:

    T C 2 Replies Last reply
    0
    • C Cedric Moonen

      v2.0 wrote:

      if you have 32 apples, it is the same as having 0x20 apples...

      It reminds me of another discussion[^] :laugh:

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #7

      Cedric Moonen wrote:

      It reminds me of another discussion[^]

      exactly... :-D i wanted to link the post, but couldn't find it... the comparison still deserves '5' :rose:

      C 1 Reply Last reply
      0
      • T toxcct

        Cedric Moonen wrote:

        It reminds me of another discussion[^]

        exactly... :-D i wanted to link the post, but couldn't find it... the comparison still deserves '5' :rose:

        C Offline
        C Offline
        chaitanya22
        wrote on last edited by
        #8

        Ya i got it guys....actually am alramed, i would like to convert the Hex to decimal value

        C 1 Reply Last reply
        0
        • C Cedric Moonen

          v2.0 wrote:

          if you have 32 apples, it is the same as having 0x20 apples...

          It reminds me of another discussion[^] :laugh:

          C Offline
          C Offline
          chaitanya22
          wrote on last edited by
          #9

          I would like to convert Hex number i,e 40 or 0x0C or 0x04B to binary value or decimal value.

          M 1 Reply Last reply
          0
          • C chaitanya22

            Hi, How to convert an array of Hex values to int in Visual C, is there any function for converting? chaitu

            R Offline
            R Offline
            Roger Stoltz
            wrote on last edited by
            #10

            The function I think you're looking for is strtol() declared in . strtol() takes a string and converts it into a long. You'll find more info about it here[^]. Hope this helps -- Roger


            It's supposed to be hard, otherwise anybody could do it!

            C 1 Reply Last reply
            0
            • C chaitanya22

              Ya i got it guys....actually am alramed, i would like to convert the Hex to decimal value

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

              chaitanya22 wrote:

              Ya i got it guys

              Nope you didn't get it, otherwise you would not have asked again. What do you want to do EXACTLY ? And don't answer 'converting hex to decimal value' because this is totally nonsense ! Again, I will express it another way: it's like asking "I have 7 apples, I want to convert these apples in hexadecimal". Mmmmh, sounds, err, how to say....special, isn't ? This is the same for your question. So, formulate your question precisely. What do you want to do ? Convert a string representing a number ?

              1 Reply Last reply
              0
              • R Roger Stoltz

                The function I think you're looking for is strtol() declared in . strtol() takes a string and converts it into a long. You'll find more info about it here[^]. Hope this helps -- Roger


                It's supposed to be hard, otherwise anybody could do it!

                C Offline
                C Offline
                chaitanya22
                wrote on last edited by
                #12

                would that function convert Hex number to binary value? for eg:0x65=1100101,, i would like to ahve so...

                C 1 Reply Last reply
                0
                • C chaitanya22

                  I would like to convert Hex number i,e 40 or 0x0C or 0x04B to binary value or decimal value.

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #13

                  why not do :

                  int i = 0x30; // or whatever hex number you have...


                  Maximilien Lincourt Your Head A Splode - Strong Bad

                  1 Reply Last reply
                  0
                  • C chaitanya22

                    would that function convert Hex number to binary value? for eg:0x65=1100101,, i would like to ahve so...

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

                    :(( :(( Even with the explanation of the apples you still don't get it. In other tearms: hex numbers and decimal numbers doesn't exist (it's a bad use of the language). Instead you should say hexadecimal REPRESENTATION or binary REPRESENTATION of a number. Let's take an example:

                    int BinValue = 0b1100101; // In binary
                    int HexValue = 0x65; // In hexadecimal
                    int DecValue = 101; // In decimal

                    In this example, all three numbers are exactly the same and if you compare them, the result will be true. Hope it is clear now.

                    1 Reply Last reply
                    0
                    • C chaitanya22

                      Hi, How to convert an array of Hex values to int in Visual C, is there any function for converting? chaitu

                      K Offline
                      K Offline
                      Konrad Windszus
                      wrote on last edited by
                      #15

                      Do you mean a string in hexadecimal format? You can do such a conversion with strtol. If you set the last parameter to 0 it does even automatically detect the number base depending on the first characters, e.g. if you have a string like 0xFF it will be converted to the integer value 255. Here is an example code: const char* szNumber = "0x1234"; char* pHelp; int nNumber = strtol(szNumber, &pHelp, 0); Regards Konrad

                      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