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. inbuild function for hexa to decimal convertion?

inbuild function for hexa to decimal convertion?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 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.
  • L Offline
    L Offline
    lgatcodeproject
    wrote on last edited by
    #1

    Hi guys can any one tell me whether there is an inbuild function that converts hexa value to decimal. I have used sscanf(charVar,"%X",intVar) when I do this the output is same as that of input (i.e., same hexa value). can any one help? Regards,:)

    lgatcodeproject

    C I CPalliniC 3 Replies Last reply
    0
    • L lgatcodeproject

      Hi guys can any one tell me whether there is an inbuild function that converts hexa value to decimal. I have used sscanf(charVar,"%X",intVar) when I do this the output is same as that of input (i.e., same hexa value). can any one help? Regards,:)

      lgatcodeproject

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

      lgatcodeproject wrote:

      converts hexa value to decimal.

      :confused: That doesn't really make sense to me. A value is a value, it's only a representation of that value that can be decimal or hexadecimal. In your sample, you have a string that contains a hexadecimal representation of a number and you store that value in the intVar. But at this time, it is a value, and not a representation anymore. There is no output possible of your intVar (if you look at it from your debugger, the debugger will show you a representation of the number, which you can change without affecting the value). I would have guessed that you want to convert a string that contains a hexa representation to a string that contains a decimal representation but your code snippet contradicts that. So, what are you trying to do exactly ?

      Cédric Moonen Software developer
      Charting control [v1.2]

      L 1 Reply Last reply
      0
      • L lgatcodeproject

        Hi guys can any one tell me whether there is an inbuild function that converts hexa value to decimal. I have used sscanf(charVar,"%X",intVar) when I do this the output is same as that of input (i.e., same hexa value). can any one help? Regards,:)

        lgatcodeproject

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        If intVar is an int, then it's not decimal, binary, hexadecimal. You can display intVar in your debugger in hex if you show intVar,x or decimal using intVar Try right clicking on the watch window and de-select the "show hex" option. Beyond that, I don't understand your problem. Iain.

        Iain Clarke appearing in spite of being begged not to by CPallini.

        1 Reply Last reply
        0
        • L lgatcodeproject

          Hi guys can any one tell me whether there is an inbuild function that converts hexa value to decimal. I have used sscanf(charVar,"%X",intVar) when I do this the output is same as that of input (i.e., same hexa value). can any one help? Regards,:)

          lgatcodeproject

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

          you have to pass the address of the int variable to sscanf, for instance:

          int i;
          sscanf("1F","%X", &i);

          sets i=31;. :)

          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.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • C Cedric Moonen

            lgatcodeproject wrote:

            converts hexa value to decimal.

            :confused: That doesn't really make sense to me. A value is a value, it's only a representation of that value that can be decimal or hexadecimal. In your sample, you have a string that contains a hexadecimal representation of a number and you store that value in the intVar. But at this time, it is a value, and not a representation anymore. There is no output possible of your intVar (if you look at it from your debugger, the debugger will show you a representation of the number, which you can change without affecting the value). I would have guessed that you want to convert a string that contains a hexa representation to a string that contains a decimal representation but your code snippet contradicts that. So, what are you trying to do exactly ?

            Cédric Moonen Software developer
            Charting control [v1.2]

            L Offline
            L Offline
            lgatcodeproject
            wrote on last edited by
            #5

            Hello, Consider this situation, I need to iterate 'iLength' number of values for a business logic. 'iLength' is a value represented in hexa. In a while loop, to perform a boundary check I am using this 'iLength' value. while(++iPosition<= iLength) My assumption is that this boudary check requires the value to be an integer is not so? If not clarify? Assuming my assumption is true how do I represent a hexa value in decimal? eg. if 'iLength' = 2b, I need 'iLength' to contain 43? How ? Kindly clarify. Thanks for your quick response. Regards, :)

            lgatcodeproject

            CPalliniC C 2 Replies Last reply
            0
            • L lgatcodeproject

              Hello, Consider this situation, I need to iterate 'iLength' number of values for a business logic. 'iLength' is a value represented in hexa. In a while loop, to perform a boundary check I am using this 'iLength' value. while(++iPosition<= iLength) My assumption is that this boudary check requires the value to be an integer is not so? If not clarify? Assuming my assumption is true how do I represent a hexa value in decimal? eg. if 'iLength' = 2b, I need 'iLength' to contain 43? How ? Kindly clarify. Thanks for your quick response. Regards, :)

              lgatcodeproject

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              lgatcodeproject wrote:

              eg. if 'iLength' = 2b, I need 'iLength' to contain 43? How ?

              You have to do nothing, supposing iLength is declared as an integer variable. :)

              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.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • L lgatcodeproject

                Hello, Consider this situation, I need to iterate 'iLength' number of values for a business logic. 'iLength' is a value represented in hexa. In a while loop, to perform a boundary check I am using this 'iLength' value. while(++iPosition<= iLength) My assumption is that this boudary check requires the value to be an integer is not so? If not clarify? Assuming my assumption is true how do I represent a hexa value in decimal? eg. if 'iLength' = 2b, I need 'iLength' to contain 43? How ? Kindly clarify. Thanks for your quick response. Regards, :)

                lgatcodeproject

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

                If iLength is an integer (which I suppose), it IS a number. iLenght contains your value and it has nothing to do with "2b" or "43" because these are only representations of your number. You have to make the difference between the value itself (which not hexa, decimal or whatever, it is just a value) and how you want to represent it (which is only used if you want to print the value in a string). Do you understand the difference ?

                lgatcodeproject wrote:

                'iLength' is a value represented in hexa

                That doesn't make sense: iLenght is an integer and that's it. An integer is never represented. If you look at it from your debugger, that's because your debugger is configured to display a representation of it in hexa, but you can change the representation to decimal without affecting the value at all.

                Cédric Moonen Software developer
                Charting control [v1.2]

                L 1 Reply Last reply
                0
                • C Cedric Moonen

                  If iLength is an integer (which I suppose), it IS a number. iLenght contains your value and it has nothing to do with "2b" or "43" because these are only representations of your number. You have to make the difference between the value itself (which not hexa, decimal or whatever, it is just a value) and how you want to represent it (which is only used if you want to print the value in a string). Do you understand the difference ?

                  lgatcodeproject wrote:

                  'iLength' is a value represented in hexa

                  That doesn't make sense: iLenght is an integer and that's it. An integer is never represented. If you look at it from your debugger, that's because your debugger is configured to display a representation of it in hexa, but you can change the representation to decimal without affecting the value at all.

                  Cédric Moonen Software developer
                  Charting control [v1.2]

                  L Offline
                  L Offline
                  lgatcodeproject
                  wrote on last edited by
                  #8

                  Hi, I understand the difference between a value and its representation. I need clarification on this, "a value means the same in what ever way it is represented am I right? then what is the real need to represent an value in different ways?" :) Regards,

                  lgatcodeproject

                  CPalliniC 1 Reply Last reply
                  0
                  • L lgatcodeproject

                    Hi, I understand the difference between a value and its representation. I need clarification on this, "a value means the same in what ever way it is represented am I right? then what is the real need to represent an value in different ways?" :) Regards,

                    lgatcodeproject

                    CPalliniC Offline
                    CPalliniC Offline
                    CPallini
                    wrote on last edited by
                    #9

                    Because a representation maybe convenient in a particular context. For instance, hexadecimal one uses exactly two digits to represent all of the values of byte (to display byte values with decimal representation you may need three digits, but a large part of decimal three-digits-numbers cannot fit in a byte); binary representation maybe opportune whenever you need to display a bit mask, and so on.. :)

                    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.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                    In testa che avete, signor di Ceprano?

                    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