The goal is to write byte array to file.
I have byte array fits[] with some bytes and then:
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);
}
}
}
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, 0xbd, 0x93, 0xbd, 0xf7 };
File.WriteAllBytes("img_correct.myf", img_correct);
byte[] img_strange = new byte[8] { 0x33, 0x08, 0x33, 0xac, 0x33, 0xe3, 0x33, 0x94 };
File.WriteAllBytes("img_strange.myf", img_strange);
}
}
}
You're using the HEX-Editor plugin from Notepad++, which seems to have a problem reading binary files.
Try with another hex editor and it should display the correct values.
Here's a screenshot of HxD and HEX-Editor displaying the same file