Hex string stream to Binary string
-
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Ðèé
-
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Ðèé
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
-
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
:) 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.
-
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Ðèé
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