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. Convert CString to Binary and Binary to CString

Convert CString to Binary and Binary to CString

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
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.
  • N Offline
    N Offline
    NewVC
    wrote on last edited by
    #1

    How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.

    CString strRet;
    CString strname="ABCDEF";

    for (int i = 0; i < strname.GetLength(); ++i) {

    CString str;
    str.Format("%2.2x", strname\[i\]);
    
    strRet += str;
    

    }
    AfxMessageBox(strRet);

    But i don't know how to convert this Binary values to CString? Plz help me:rose:

    CPalliniC S K 3 Replies Last reply
    0
    • N NewVC

      How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.

      CString strRet;
      CString strname="ABCDEF";

      for (int i = 0; i < strname.GetLength(); ++i) {

      CString str;
      str.Format("%2.2x", strname\[i\]);
      
      strRet += str;
      

      }
      AfxMessageBox(strRet);

      But i don't know how to convert this Binary values to CString? Plz help me:rose:

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

      Your function merely transforms the original string in another one, the latter containing the character codes of the former one, represented as two-digits hexadecimal values. What do you want to do, really? :)

      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
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • N NewVC

        How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.

        CString strRet;
        CString strname="ABCDEF";

        for (int i = 0; i < strname.GetLength(); ++i) {

        CString str;
        str.Format("%2.2x", strname\[i\]);
        
        strRet += str;
        

        }
        AfxMessageBox(strRet);

        But i don't know how to convert this Binary values to CString? Plz help me:rose:

        S Offline
        S Offline
        SandipG
        wrote on last edited by
        #3

        Do you want that user should not be able to read the strings when they open the files in notepad or some text editor?? If yes i will suggest to use some simple encryption rather than converting the string to hex/binary.

        Regards, Sandip.

        1 Reply Last reply
        0
        • N NewVC

          How can I convert a CString variable to a binary string, so that I can write it to the text file in binary form and Read CString form? i am converting CString to Binary like this.

          CString strRet;
          CString strname="ABCDEF";

          for (int i = 0; i < strname.GetLength(); ++i) {

          CString str;
          str.Format("%2.2x", strname\[i\]);
          
          strRet += str;
          

          }
          AfxMessageBox(strRet);

          But i don't know how to convert this Binary values to CString? Plz help me:rose:

          K Offline
          K Offline
          KarstenK
          wrote on last edited by
          #4

          in your code you can do easily this: CString strname="ABCDEF";//if Unicode use the macro => TEXT("ABCDEF") :cool: //no transforming needed AfxMessageBox(strname); writing and reading data have only to be compatible. There is a tiny MFC class for it: http://msdn.microsoft.com/en-us/library/aa314304(VS.60).aspx[^] try it out and step-debug in the sources.

          Greetings from Germany

          T 1 Reply Last reply
          0
          • K KarstenK

            in your code you can do easily this: CString strname="ABCDEF";//if Unicode use the macro => TEXT("ABCDEF") :cool: //no transforming needed AfxMessageBox(strname); writing and reading data have only to be compatible. There is a tiny MFC class for it: http://msdn.microsoft.com/en-us/library/aa314304(VS.60).aspx[^] try it out and step-debug in the sources.

            Greetings from Germany

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

            KarstenK wrote:

            ";//if Unicode use the macro => TEXT("ABCDEF")

            no, use TEXT() ( or _T() ) anytime you use CString with literals. if using CStringW, then prepend the literals with L, and if using CStringA, then don't do much as writing the literal like you normally do. _T() will extend to the unicode or ansi version depending on the compilation mode, so you don't have to bother about it.

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

            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