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. Hex string stream to Binary string

Hex string stream to Binary string

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
4 Posts 3 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.
  • R Offline
    R Offline
    RS Ratheesh
    wrote on last edited by
    #1

    Hi, I need C or C++ code to convert the hex string to the binary string please can any one help me. Eg Hex Data: C1 E1 08 0F B6 C0 0B C8 8D 45 F4 50 89 4D F8 FF 15 48 70 40 00 83 45 F0 04 89 45 14 50 8D 45 E4 50 FF 75 0C FF 15 4C 72 40 00 FF 75 14 FF D3 83 45 E8 04 39 7D E8 0F 8C 77 FF FF FF 83 7E 58 FF 74 65 FF 76 34 FF 15 4C 70 40 00 85 C0 89 45 14 74 55 8B 7D 0C 6A 01 57 C7 45 E4 10 00 00 00 C7 45 E8 08 00 00 00 FF 15 50 70 40 00 FF 76 58 57 FF 15 54 70 40 00 FF 75 14 8B 35 58 70 40 00 57 FF D6 89 45 0C 8D 45 E4 68 20 08 00 00 50 6A FF 68 40 3F 42 00 57 FF 15 50 72 40 00 FF 75 To Binary Data: Vÿ q@ ‹ø;ûteÿuWÿq@ ‹ð;ót=9]ä‰]ütÿuäèéóÿÿÿÖ…Àt1ÇEü ë(h @ h°@ h PB h  ÿuøÿÖƒÄë ÿuj÷èÊ, 9]èuWÿq@ ë jöëjçè™óÿÿSÿq@ é jðèó j߉EÐèé

    CPalliniC D 2 Replies Last reply
    0
    • R RS Ratheesh

      Hi, I need C or C++ code to convert the hex string to the binary string please can any one help me. Eg Hex Data: C1 E1 08 0F B6 C0 0B C8 8D 45 F4 50 89 4D F8 FF 15 48 70 40 00 83 45 F0 04 89 45 14 50 8D 45 E4 50 FF 75 0C FF 15 4C 72 40 00 FF 75 14 FF D3 83 45 E8 04 39 7D E8 0F 8C 77 FF FF FF 83 7E 58 FF 74 65 FF 76 34 FF 15 4C 70 40 00 85 C0 89 45 14 74 55 8B 7D 0C 6A 01 57 C7 45 E4 10 00 00 00 C7 45 E8 08 00 00 00 FF 15 50 70 40 00 FF 76 58 57 FF 15 54 70 40 00 FF 75 14 8B 35 58 70 40 00 57 FF D6 89 45 0C 8D 45 E4 68 20 08 00 00 50 6A FF 68 40 3F 42 00 57 FF 15 50 72 40 00 FF 75 To Binary Data: Vÿ q@ ‹ø;ûteÿuWÿq@ ‹ð;ót=9]ä‰]ütÿuäèéóÿÿÿÖ…Àt1ÇEü ë(h @ h°@ h PB h  ÿuøÿÖƒÄë ÿuj÷èÊ, 9]èuWÿq@ ë jöëjçè™óÿÿSÿq@ é jðèó j߉EÐèé

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

      Since your string is well formatted, it's pretty simple, for instance

      char szHex[] = "C1 E1 08 0F B6 C0 0B";
      const unsigned int SIZE = sizeof(szHex)/sizeof(szHex[0]) / 3;
      unsigned char pBinary[SIZE];
      for (int i=0; i<SIZE; i++)
      {
      if ( sscanf(szHex + 3 * i, "%2X", pBinary+i) != 1) break;
      }

      However, I see the result you're expecting is quite different. How can, for instance, you map 0xC1 to 'V'? :)

      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]

      modified on Tuesday, June 9, 2009 3:32 AM

      In testa che avete, signor di Ceprano?

      R 1 Reply Last reply
      0
      • CPalliniC CPallini

        Since your string is well formatted, it's pretty simple, for instance

        char szHex[] = "C1 E1 08 0F B6 C0 0B";
        const unsigned int SIZE = sizeof(szHex)/sizeof(szHex[0]) / 3;
        unsigned char pBinary[SIZE];
        for (int i=0; i<SIZE; i++)
        {
        if ( sscanf(szHex + 3 * i, "%2X", pBinary+i) != 1) break;
        }

        However, I see the result you're expecting is quite different. How can, for instance, you map 0xC1 to 'V'? :)

        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]

        modified on Tuesday, June 9, 2009 3:32 AM

        R Offline
        R Offline
        RS Ratheesh
        wrote on last edited by
        #3

        :) No i pasted just for a sample output that i need, its not the correct output i copied a part from the output, Thanks for your post.

        1 Reply Last reply
        0
        • R RS Ratheesh

          Hi, I need C or C++ code to convert the hex string to the binary string please can any one help me. Eg Hex Data: C1 E1 08 0F B6 C0 0B C8 8D 45 F4 50 89 4D F8 FF 15 48 70 40 00 83 45 F0 04 89 45 14 50 8D 45 E4 50 FF 75 0C FF 15 4C 72 40 00 FF 75 14 FF D3 83 45 E8 04 39 7D E8 0F 8C 77 FF FF FF 83 7E 58 FF 74 65 FF 76 34 FF 15 4C 70 40 00 85 C0 89 45 14 74 55 8B 7D 0C 6A 01 57 C7 45 E4 10 00 00 00 C7 45 E8 08 00 00 00 FF 15 50 70 40 00 FF 76 58 57 FF 15 54 70 40 00 FF 75 14 8B 35 58 70 40 00 57 FF D6 89 45 0C 8D 45 E4 68 20 08 00 00 50 6A FF 68 40 3F 42 00 57 FF 15 50 72 40 00 FF 75 To Binary Data: Vÿ q@ ‹ø;ûteÿuWÿq@ ‹ð;ót=9]ä‰]ütÿuäèéóÿÿÿÖ…Àt1ÇEü ë(h @ h°@ h PB h  ÿuøÿÖƒÄë ÿuj÷èÊ, 9]èuWÿq@ ë jöëjçè™óÿÿSÿq@ é jðèó j߉EÐèé

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

          How would you do this using pencil and paper?

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          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