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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Urgent Convert from CString to hexadecimal

Urgent Convert from CString to hexadecimal

Scheduled Pinned Locked Moved C / C++ / MFC
12 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.
  • I imanos

    i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time

    emma :)

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

    ::sscanf(s, "%x", k);


    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

    I 1 Reply Last reply
    0
    • I imanos

      i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time

      emma :)

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

      Have a look at ::strtol(...)[^].


      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      I 1 Reply Last reply
      0
      • T toxcct

        ::sscanf(s, "%x", k);


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        I Offline
        I Offline
        imanos
        wrote on last edited by
        #4

        no i want to enter it as i send before it is given in the code and not to be get as input

        emma :)

        CPalliniC T 2 Replies Last reply
        0
        • I imanos

          i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time

          emma :)

          P Offline
          P Offline
          Paresh Chitte
          wrote on last edited by
          #5

          Will CString::Format be helpful ? Regards, Paresh.

          I 1 Reply Last reply
          0
          • I imanos

            i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time

            emma :)

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

            you can do:

            k = strtol(s, &pStop, 16);

            where pStop is a char pointer (see strtol documentation). of course you'll get k=0x1E. :)

            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.

            In testa che avete, signor di Ceprano?

            I 1 Reply Last reply
            0
            • I imanos

              no i want to enter it as i send before it is given in the code and not to be get as input

              emma :)

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

              look, i use **ss**canf() (with 2 s), not scanf()


              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              1 Reply Last reply
              0
              • I imanos

                no i want to enter it as i send before it is given in the code and not to be get as input

                emma :)

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

                imanos wrote:

                it is given in the code and not to be get as input

                and indeed sscanf does what you are requiring. see here [^]. :)

                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.

                In testa che avete, signor di Ceprano?

                I 1 Reply Last reply
                0
                • CPalliniC CPallini

                  imanos wrote:

                  it is given in the code and not to be get as input

                  and indeed sscanf does what you are requiring. see here [^]. :)

                  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.

                  I Offline
                  I Offline
                  imanos
                  wrote on last edited by
                  #9

                  Thanks a lot it worked waaaaaaaaaaaaaw thanks in advance ;)

                  emma :)

                  1 Reply Last reply
                  0
                  • R Roger Stoltz

                    Have a look at ::strtol(...)[^].


                    "It's supposed to be hard, otherwise anybody could do it!" - selfquote
                    "High speed never compensates for wrong direction!" - unknown

                    I Offline
                    I Offline
                    imanos
                    wrote on last edited by
                    #10

                    Thanks for ur valuable time ur all great actually the sscanf worked for me and i'm sure this one works too so thanks

                    emma :)

                    1 Reply Last reply
                    0
                    • P Paresh Chitte

                      Will CString::Format be helpful ? Regards, Paresh.

                      I Offline
                      I Offline
                      imanos
                      wrote on last edited by
                      #11

                      actually i didn't try it but sscanf was just fine Thanks for ur valuable time ur all great thanks

                      emma :)

                      1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        you can do:

                        k = strtol(s, &pStop, 16);

                        where pStop is a char pointer (see strtol documentation). of course you'll get k=0x1E. :)

                        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.

                        I Offline
                        I Offline
                        imanos
                        wrote on last edited by
                        #12

                        u know sscanf worked for me but sure i'll try all the solutions to have them all Thanks for ur valuable time ur all great thanks

                        emma :)

                        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