c# 读取二进制的问题,请高手帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/20 13:54:06
private void loadtxt_Click(object sender, EventArgs e)
{

OpenFileDialog ofDlg = new OpenFileDialog();
ofDlg.Filter = "Text (*.txt)|*.txt|All Files (*.*)|*.*"; //"All Files (*.*)|*.*";
if (ofDlg.ShowDialog() == DialogResult.OK)
{

FileStream Fs = new FileStream(ofDlg.FileName, FileMode.Open, FileAccess.Read);

int File_Log = (int)Fs.Length;

byte[] File_Text = new byte[File_Log];

Fs.Read(File_Text, 0, File_Log);

Fs.Close();

string s = null;
for (int i = 0; i < File_Text.Length; i++)
{
s += Convert.ToSByte(File_Text[i]).ToString();
}
MessageBox.Show(s);

}

现再可以打开TXT文件并

有个进制转换的方法
public string ConvertString(string value, int fromBase, int toBase){
long intValue = Convert.ToInt64(value, fromBase);
return textBox1.Text=Convert.ToString(intValue, toBase);}
//value就是你TXT中的内容fromBale就是你输入的几进制的值.比如A就是十六进制的值.toBase就是你要转换成的几进制.当然你要转换成二进制这里就是2了.我知道你的意思.你是读取A的ascii码值再转换成二进制.这就只有你自己想哈如何融合进去了.

直接读是读不出来,你可以读出来再转一下。
参考:
http://topic.csdn.net/t/20041225/11/3675204.html

不可以吧,机器码就是已经编译好了的