在这一点上,大多数人都会想到"这会发病啊......"
byte[] dataB= System.Text.Encoding.ASCII.GetBytes(data);
Run Code Online (Sandbox Code Playgroud)
但是..我遇到的问题是我需要字节的确切值,没有编码只是每个字节的纯值.例如,如果字符串的值是(0xFF32),我希望它也将它转换为{255,50}.他的理由是我有一个文件格式我试图读取哪些存储int作为字节保存它们然后在程序打开时读取它们.
这是我到目前为止:
...
dialog.InitialDirectory =
Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) +
"/Test";
dialog.Title="Open File";
if (dialog.ShowDialog(this) == DialogResult.OK)
{
StreamReader reader = new StreamReader(dialog.FileName);
string data = reader.ReadToEnd();
reader.Close();
byte[] fileC = System.Text.Encoding.ASCII.GetBytes(data);
File_Read(dialog.FileName,fileC);
}
...
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试读取文件时,它会将0xFF的文件修改为0x3F,因为0xFF大于127且0x3F是?
对不起,如果我看起来有点混乱:)
谢谢,迈克尔