c# – Strange Notepad HEX-editor插件
目标是将字节数组写入文件.
我有字节数组[]与一些字节,然后: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace _32_to_16 { class Program { static void Main(string[] args) { byte[] fits = File.ReadAllBytes("1.myf"); byte[] img = new byte[fits.Length / 2]; for (int i = 0; i < fits.Length; i += 4) //Drops 2 high bytes { img[i/2] = fits[i + 2]; img[i/2 + 1] = fits[i + 3]; } File.WriteAllBytes("new.myf",img); } } } 在写入文件之前,img []具有相同的值: > img [0] = 0x31 写入文件后,在HEX编辑器中我看到了 > 00000000:31 27 31 3f和其他错误值. 有时,使用其他fits []值,img []数组正确写入文件.我做错了什么? 我简化了代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace _32_to_16 { class Program { static void Main(string[] args) { byte[] img_correct = new byte[8] { 0xbd,0x19,0xbd,0x72,0x93,0xf7 }; File.WriteAllBytes("img_correct.myf",img_correct); byte[] img_strange = new byte[8] { 0x33,0x08,0x33,0xac,0xe3,0x94 }; File.WriteAllBytes("img_strange.myf",img_strange); } } } 在HEX-editor img_correct.myf看起来像这样: 在HEX-editor中,img_strange.myf看起来像这样: 解决方法
您正在使用记事本中的HEX-Editor插件,该插件似乎有一个
problem reading binary files.
尝试使用其他十六进制编辑器,它应显示正确的值. 这是HxD和HEX-Editor的屏幕截图,显示相同的文件 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |