954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Hex to String

I am trying to write some information out to a file. I have a string in hex values and I need to write this out to the output file. The hex string I have is 4b70 4772 64. The string equivalent is KpGrd.

I have:

char a[] = "4b7047726400";

Then when I try to write it out to the output file it writes "4b7047726400" as a string and not hex values. I need it to be written as hex values where byte 1 woiuld be 4b, byte 2 would be 70, etc. Does it need to be converted to the string equivalent of KpGrd and then be written to the output file? Basically, when I open up the output file in a Hex editor I should see the first 6 bytes as 4b 70 47 72 64 and the string equivalent would be KpGrd. thanks.

ashkash
Newbie Poster
24 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

You need to do some converting. Do some research on the std::hex stream manipulator for ideas.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Thanks I was able to figure it out.

ashkash
Newbie Poster
24 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Hmm, hex manipulator on the C language forum...
Be afraid of pure C fanatics ;)...

ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You