如何把for循环里的chirp存到一个数组里呢?转化为16位二进制如何写入文件

weixin_38052463 2017-10-20 12:26:49
public Form1()
{
InitializeComponent();
Stopwatch sw = new Stopwatch();
sw.Start();
string filePath = System.AppDomain.CurrentDomain.
SetupInformation.ApplicationBase + @"cp.txt";//设置路径将文件保存在目标文件下


double t0 = 0, f0 = 100000d;
//double beta = (f1 - f0) / t1;
double beta = 900000d/4.194304d;
double chirp = 0;
int c;
int[] bases = { 2, 8, 10, 16 };
int[] numbers = { Int32.MinValue, -19327543, -13621, -18, 12,
19142, Int32.MaxValue };
using(FileStream fs = File.Create(filePath))
{

for (int i=0; i<=167772160; i++)
{
chirp = Math.Cos(Math.PI * (2 * f0 + beta * t0) * t0);
t0 += 0.000000025;
chirp = Math.Round(chirp * 2046);
chirp = chirp*2 + 2046;
c = (int)chirp;
foreach (int baseValue in bases)
{
Console.WriteLine("Base {0} conversion:", baseValue);
foreach (int number in numbers)
{
Console.WriteLine(" {0,-15} --> 0x{1}",
number, Convert.ToString(number, baseValue));
}
}

}

sw.Stop();
MessageBox.Show("耗时为: " + sw.ElapsedMilliseconds.ToString() + " ms");

}
}
...全文
24 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧