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 an int to a hex String

converting an int to a hex String

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
5 Posts 5 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.
  • B Offline
    B Offline
    BoudewijnEctor
    wrote on last edited by
    #1

    Hi, How can I convert an int (or a double) to a CString, wich contains a hex value. Example: I've got an int, called 'a', with value 33. And I need to get a String with the hexadeciaml value of 'a', wich means (in this case) that I need a CString containing "21". Do you know wether is some fkind of function for this??? Thanks

    M M L V 4 Replies Last reply
    0
    • B BoudewijnEctor

      Hi, How can I convert an int (or a double) to a CString, wich contains a hex value. Example: I've got an int, called 'a', with value 33. And I need to get a String with the hexadeciaml value of 'a', wich means (in this case) that I need a CString containing "21". Do you know wether is some fkind of function for this??? Thanks

      M Offline
      M Offline
      michael_cowan
      wrote on last edited by
      #2

      Here you go. As always thrown together and untested but should work.int nValue = 33; CString str; str.Format("%x", nValue);

      There are 10 types of people in the world Those who understand binary, and those who don't

      1 Reply Last reply
      0
      • B BoudewijnEctor

        Hi, How can I convert an int (or a double) to a CString, wich contains a hex value. Example: I've got an int, called 'a', with value 33. And I need to get a String with the hexadeciaml value of 'a', wich means (in this case) that I need a CString containing "21". Do you know wether is some fkind of function for this??? Thanks

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        See the FAQ 6.3 How can I change a number into its string representation, or vice versa? [^] --Mike-- Ericahist [updated Oct 26] | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.   -- Michael P. Butler in the Lounge

        1 Reply Last reply
        0
        • B BoudewijnEctor

          Hi, How can I convert an int (or a double) to a CString, wich contains a hex value. Example: I've got an int, called 'a', with value 33. And I need to get a String with the hexadeciaml value of 'a', wich means (in this case) that I need a CString containing "21". Do you know wether is some fkind of function for this??? Thanks

          L Offline
          L Offline
          LozEvans
          wrote on last edited by
          #4

          Hiya, int a =33; CString lHexValue; lHexValue.Format("%x",a); Cheers Loz

          1 Reply Last reply
          0
          • B BoudewijnEctor

            Hi, How can I convert an int (or a double) to a CString, wich contains a hex value. Example: I've got an int, called 'a', with value 33. And I need to get a String with the hexadeciaml value of 'a', wich means (in this case) that I need a CString containing "21". Do you know wether is some fkind of function for this??? Thanks

            V Offline
            V Offline
            vladimir_india
            wrote on last edited by
            #5

            Hey u can use this : long str2hex(char *str) { long hwnd=0; char ch; ::CharUpperBuff(str,8); for(int i=0;i<8;i++) { ch = str[i]; if(ch>=48 && ch<=57) hwnd+=(ch-48)*1<<(4*(7-i)); else if (ch>=65 && ch<=70) hwnd+=(ch-65+10)*1<<(4*(7-i)); } return hwnd; } -Vladimir India:)

            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