c# - Charecter Textfile to binary Textfile -


i have been searching everywhere have had no luck yet.

i have text file contains set of records , trying convert , save 1's , 0's .. every time use

byte [] arr=encoding.utf8.getbytes(recordss) ; 

and write using byte writer still have same record file no difference.

so question there way convert string binary , write file in binary format. using c# way

thanks in advance , here code far

public static void serialdata() {     filestream recfile = new filestream("records.txt", filemode.open, fileaccess.readwrite);   //file used records      streamreader recordread = new streamreader(recfile);      string recordss = recordread.readtoend();        //reads record file      recordread.close();     recfile.close();      byte [] arr=encoding.utf8.getbytes(recordss) ;      filestream file = new filestream("temp.txt", filemode.create, fileaccess.write);     streamwriter binfile = new streamwriter(file);      for(int =0; < arr.count();i++)         binfile.writeline(arr[i]);      binfile.close();     file.close(); } 

there's built-in function convert integer-type values strings binary representation. try replacing line

binfile.writeline(arr[i]); 

by line

binfile.writeline(     convert.tostring(arr[i], 2) ); 

convert.tostring() convert input representation in given base. in case, choose 2 base binary representation. other common values 8 octal, or 16 hexadecimal.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -