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 change interpretation int - hex

how to change interpretation int - hex

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
8 Posts 6 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 Offline
    T Offline
    tbrake
    wrote on last edited by
    #1

    Hallo How can i change the interpretation of a variable. Example int text = 123456; // editable by user !! ... // On one position I need to convert to 0x123456 ... THX Timen

    _ S T D N 5 Replies Last reply
    0
    • T tbrake

      Hallo How can i change the interpretation of a variable. Example int text = 123456; // editable by user !! ... // On one position I need to convert to 0x123456 ... THX Timen

      _ Offline
      _ Offline
      _anil_
      wrote on last edited by
      #2

      This should work!!!

        int nText = 12345;
        char  szText[10];
        int nHex =0;
        itoa(12345, szText, 10);
        nHex = strtol( szText, NULL, 16);
      

      Regards Anil

      1 Reply Last reply
      0
      • T tbrake

        Hallo How can i change the interpretation of a variable. Example int text = 123456; // editable by user !! ... // On one position I need to convert to 0x123456 ... THX Timen

        S Offline
        S Offline
        Steen Krogsgaard
        wrote on last edited by
        #3

        Either write your own converter (multiply each digit with powers of 16), or convert to string using sprintf and convert back to hex using sscanf. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

        C 1 Reply Last reply
        0
        • S Steen Krogsgaard

          Either write your own converter (multiply each digit with powers of 16), or convert to string using sprintf and convert back to hex using sscanf. Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

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

          Steen Krogsgaard wrote:

          Either write your own converter (multiply each digit with powers of 16), or convert to string using sprintf and convert back to hex using sscanf.

          This makes non-sense. A number is neither in decimal, in hexa, or whatever else; it is just a number. Its representation may change but the number will always be the same. You can say 0x14 or 20 or 0b10100, all these three strings represent the same number. -- modified at 7:23 Friday 2nd June, 2006 Sorry, I misread the thread :)


          Cédric Moonen Software developer
          Charting control

          1 Reply Last reply
          0
          • T tbrake

            Hallo How can i change the interpretation of a variable. Example int text = 123456; // editable by user !! ... // On one position I need to convert to 0x123456 ... THX Timen

            T Offline
            T Offline
            tbrake
            wrote on last edited by
            #5

            Hallo 1. Well at least it makes sence. cause i have to controll some hardware. To calculate the needed commands the shortes way is to interprete int as Hex bit shift this and the result is the needed command. Outherwice if you cant see the sence then become a lectural 2. int - char - hex is what i have and this is as fast doing a lot of if else combinations - well but i need somthing fast - much faster ?!?! Well the THX Timen:->

            S 1 Reply Last reply
            0
            • T tbrake

              Hallo 1. Well at least it makes sence. cause i have to controll some hardware. To calculate the needed commands the shortes way is to interprete int as Hex bit shift this and the result is the needed command. Outherwice if you cant see the sence then become a lectural 2. int - char - hex is what i have and this is as fast doing a lot of if else combinations - well but i need somthing fast - much faster ?!?! Well the THX Timen:->

              S Offline
              S Offline
              Steen Krogsgaard
              wrote on last edited by
              #6

              tbrake wrote:

              2. int - char - hex is what i have and this is as fast doing a lot of if else combinations - well but i need somthing fast - much faster ?!?!

              John Simmons, 05/31/2006

              1 Reply Last reply
              0
              • T tbrake

                Hallo How can i change the interpretation of a variable. Example int text = 123456; // editable by user !! ... // On one position I need to convert to 0x123456 ... THX Timen

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

                tbrake wrote:

                int text = 123456; // editable by user !! ... // On one position I need to convert to 0x123456

                123456 in base-16 is 0x1E240. Use itoa() or sscanf() to do the conversion.


                "The largest fire starts but with the smallest spark." - David Crow

                1 Reply Last reply
                0
                • T tbrake

                  Hallo How can i change the interpretation of a variable. Example int text = 123456; // editable by user !! ... // On one position I need to convert to 0x123456 ... THX Timen

                  N Offline
                  N Offline
                  Nibu babu thomas
                  wrote on last edited by
                  #8

                  tbrake wrote:

                  How can i change the interpretation of a variable.

                  cout<<hex<<123233;//displays in hexadecimal format.
                  cout<<oct<<121223;//displays in octal format.
                  cout<<dec<<12323;//displays in decimal format.


                  Nibu thomas A Developer Programming tips[^]  My site[^]

                  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