0

So I have a file that I need to have in either binary or hex format. Everything that I've been able to find basically says to store the text in a string and convert it to binary or hex from there, but I cant do it this way. The file was written using its own private character set that uses null and system hex codes, so notepad doesn't know what to do with these characters and replaces it with wrong characters and spaces. This distorts the information so it wont be correct if I try to convert it to binary/hex.

I really just need to have the binary/hex information stored in a string or text box so I can work with it. I don't really need it to be saved as a file.

5
  • No offense, but I've never heard of a non-binary file, unless you're on a quantum computer. What exactly are you trying to do here? Can you post an example, as well as what you have tried doing that did not work?
    – lc.
    Jul 26, 2013 at 9:15
  • No, I dont think you understood. It is a binary file. Its a .PTC file format, but can be converted back to a .txt file. But I need to get the binary information BEFORE its attempted to be converted into ascii because its distorting the information. http://img42.com/XcMVd this is an example after its been converted into text. the top is wrong, the bottom is me manually taking the hex and converting it. I have to get the binary data before its attempted to be converted. Jul 26, 2013 at 9:48
  • That image is using a custom font that i made that represents the character set the program was made with, so the bottom one is EXACTLY how its suppose to look, but i had to use a hex editor to go in and copy the hex data so i could convert it. I need code to automatically read the binary/hex codes so i can manually decrypt the hex information into the correct characters. I hope that makes sense. Jul 26, 2013 at 9:53
  • 1
    Why don't you just open the file as a stream?
    – Alexander
    Jul 26, 2013 at 10:22
  • I tried to use a filestream code snippit i found, but i really dont know how to use them. THINK i have the data in a byte array now. I'm not certain though because I don't know how to convert it from a byte array to a single string in binary format, and I dont understand the buffer size or if thats going to cause it not to be able to read the whole file. Jul 26, 2013 at 10:34

1 Answer 1

0

Never mind, I finally figured it out. I used a file stream to read the data byte by byte. I didn't understand how to convert this as the first byte data in the array was showing as 80 when i knew the binary data should've been "1010000" (i didn't realize at that time that 80 was the decimal format).

Anyways I used the bitconverter.tostring and it put everything together and converted it to hexadecimal format. So i'm all good now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.