我有一个简单的功能,抓住从C硬盘序列号:\驱动器,并把它转换成字符串:写作硬盘序列串为二进制文件
然后我试图转换将上面的字符串转换成ASCII码,然后将其写入二进制文件,我遇到的问题是,在转换此字符串并使用streamwriter保存文件并在十六进制编辑器中打开该文件时,我看到更多的字节我原本想这样写例如“16342D1F4A61BC”
将出现为:08 16 34 2d 1f 4a 61 c2 bc
它添加在那里不知何故08和C2 ......
更完整版如下:
string constructor2 = "16342D1F4A61BC";
string StrValue = "";
while (constructor2.Length > 0)
{
StrValue += System.Convert.ToChar(System.Convert.ToUInt32(constructor2.Substring(0, 2), 16)).ToString();
// Remove from the hex object the converted value
constructor2 = constructor2.Substring(2, constructor2.Length - 2);
}
FileStream writeStream;
try
{
writeStream = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + "\\license.mgr", FileMode.Create);
BinaryWriter writeBinay = new BinaryWriter(writeStream);
writeBinay.Write(StrValue);
writeBinay.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
谁能帮助我了解这些在获取添加?
你不能直接写输出? – tofutim 2011-05-27 17:34:17
while循环的目的是什么?有一个方便的Encoding.ASCII.GetBytes(字符串),它会从任何字符串返回必要的字节。 – Joe 2011-05-27 17:34:22
我想你是说当你以十六进制查看你的输出文件时,你想看到硬盘ID的十六进制表示。 – tofutim 2011-05-27 17:48:56