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. Conversion Hex string to ASCII value

Conversion Hex string to ASCII value

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
10 Posts 4 Posters 11 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.
  • R Offline
    R Offline
    Ram Murali
    wrote on last edited by
    #1

    Dear All, I have some problem in converting Hex string to ASCII value. For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P". If i know the value to convert i can just use CString str; str = "\x50"; to convert to ASCII value. But the Hex value is entered by the user. So I dont know how to do that. Can Anyone please help me in this? Thanks in Advance.

    Regards, Ram

    R D 2 Replies Last reply
    0
    • R Ram Murali

      Dear All, I have some problem in converting Hex string to ASCII value. For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P". If i know the value to convert i can just use CString str; str = "\x50"; to convert to ASCII value. But the Hex value is entered by the user. So I dont know how to do that. Can Anyone please help me in this? Thanks in Advance.

      Regards, Ram

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

      Would ::strtol() help you in this situation? Info here.[^]


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

      R 1 Reply Last reply
      0
      • R Roger Stoltz

        Would ::strtol() help you in this situation? Info here.[^]


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

        R Offline
        R Offline
        Ram Murali
        wrote on last edited by
        #3

        Can you please give me an example?

        Regards, Ram

        R 1 Reply Last reply
        0
        • R Ram Murali

          Can you please give me an example?

          Regards, Ram

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

          Ram Murali wrote:

          Can you please give me an example?

          :confused: I provided a link in my previous post to MSDN. Follow it and you will find another link in the MSDN article to an example.


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

          R 1 Reply Last reply
          0
          • R Roger Stoltz

            Ram Murali wrote:

            Can you please give me an example?

            :confused: I provided a link in my previous post to MSDN. Follow it and you will find another link in the MSDN article to an example.


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

            R Offline
            R Offline
            Ram Murali
            wrote on last edited by
            #5

            But this function is to convert str to long. how can i get a character?

            Regards, Ram

            N R 2 Replies Last reply
            0
            • R Ram Murali

              But this function is to convert str to long. how can i get a character?

              Regards, Ram

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              char cAsciivalue = nlong;// the long value u got

              nave

              1 Reply Last reply
              0
              • R Ram Murali

                But this function is to convert str to long. how can i get a character?

                Regards, Ram

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

                Ram Murali wrote:

                But this function is to convert str to long.

                Of course; and that return value is the ASCII code for the character. E.g. if your user has input "50" the long return value of ::strtol() will be 0x50, which is 80 in decimal format, and this is the ASCII character code for 'P'.


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

                R 1 Reply Last reply
                0
                • R Ram Murali

                  Dear All, I have some problem in converting Hex string to ASCII value. For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P". If i know the value to convert i can just use CString str; str = "\x50"; to convert to ASCII value. But the Hex value is entered by the user. So I dont know how to do that. Can Anyone please help me in this? Thanks in Advance.

                  Regards, Ram

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

                  Ram Murali wrote:

                  For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P".

                  CString strHex = "0x50";
                  char *pEnd;
                  printf("%c\n", strtol(strHex, &pEnd, 16));


                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                  "Judge not by the eye but by the heart." - Native American Proverb

                  R 1 Reply Last reply
                  0
                  • D David Crow

                    Ram Murali wrote:

                    For example, I have Hex string of "50" and I would like to display the ASCII equivalent "P".

                    CString strHex = "0x50";
                    char *pEnd;
                    printf("%c\n", strtol(strHex, &pEnd, 16));


                    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                    "Judge not by the eye but by the heart." - Native American Proverb

                    R Offline
                    R Offline
                    Ram Murali
                    wrote on last edited by
                    #9

                    Thanks a lot. Its working well.

                    Regards, Ram

                    1 Reply Last reply
                    0
                    • R Roger Stoltz

                      Ram Murali wrote:

                      But this function is to convert str to long.

                      Of course; and that return value is the ASCII code for the character. E.g. if your user has input "50" the long return value of ::strtol() will be 0x50, which is 80 in decimal format, and this is the ASCII character code for 'P'.


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

                      R Offline
                      R Offline
                      Ram Murali
                      wrote on last edited by
                      #10

                      Thanks for your effort to solve my problem. Its working well. Thanks again.

                      Regards, Ram

                      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