Good day! For a bad hour I can not figure out the question.

A piece of code on c ++

unsigned short cpoint1; TFileStream* wfs1=new TFileStream("Signal1.wav",fmCreate); for (i=0; i<m ; i++) { cpoint1 = wfmmas1[i]; wfs1->Write(&cpoint1,2); } delete wfs1; 

Trying to rewrite to c #

 ushort cpoint1; FileStream wfs1 = new FileStream("Signal1.wav", FileMode.Create); UnicodeEncoding uniEncoding = new UnicodeEncoding(); for (i=0; i<m ; i++) { cpoint1 = wfmmas1[i]; wfs1.Write(uniEncoding.GetBytes(Convert.ToString(astr)), 2, uniEncoding.GetByteCount(Convert.ToString(astr))-2); } wfs2.Close(); 

The problem is that the files created in the first and second case are different. I will be glad to any help! =)

  • Specifically, that you can not !! - IGOR

1 answer 1

ushort cpoint1;

  FileStream wfs1 = new FileStream("Signal1.wav", FileMode.Create); UnicodeEncoding uniEncoding = new UnicodeEncoding(); for (int i = 0; i < m; i++) { cpoint1 = wfmmas1[i]; wfs1.Write(uniEncoding.GetBytes(Convert.ToString(cpoint1)), 0, uniEncoding.GetByteCount(Convert.ToString(cpoint1))); } wfs1.Close(); 
  • Igor found my shoals, but the result was still different. out of the situation as follows: ushort cpoint1; FileStream wfs1 = new FileStream ("Signal1.wav", FileMode.Create); for (i = 0; i <m; i ++) {cpoint1 = wfmmas1 [i]; byte [] bytes = BitConverter.GetBytes (cpoint1); wfs1.Write (bytes, 0,2); } wfs1.Close (); - grigo