none
How to Write Raw Hex to a File? RRS feed

  • Question

  • How can I output raw hex codes to a file?
    When I do (StreamWriter)w.Write((Int8)65); I get the string "65" in the file, but I expected the letter "A" (ascii 65).
    Tuesday, December 13, 2005 11:39 AM

Answers

  • Perhaps you are looking for BinaryWriter.Write(Byte) method where Byte is a single Byte variable or an element of a byte array.  I beleive you can also write an entrie byte array with this method.
    Tuesday, December 13, 2005 1:08 PM

All replies

  • i dont know what is your scenario to tell you what is the best thing you can do

    but to write any character depend on his ascii representation you can just use
    chr() function like

    (streamWriter)w.write(chr(65)) which will print for you A
    Tuesday, December 13, 2005 12:17 PM
  • Your problem is that StreamWriter is for writing text files and therefore will convert everything to text before writing it out.  I would recommend that you instead cast the value to a char.  This causes the writer to write out the character equivalent.

    (StreamWriter)w.Write((char)65);

    Alternatively store the list of values that you want to write in a char[] and then call that overload.  It would prove to be faster.

    Michael Taylor - 12/13/05
    Tuesday, December 13, 2005 12:22 PM
    Moderator
  • Perhaps you are looking for BinaryWriter.Write(Byte) method where Byte is a single Byte variable or an element of a byte array.  I beleive you can also write an entrie byte array with this method.
    Tuesday, December 13, 2005 1:08 PM