public void ExportTo(IntelHexFile HexFile, Stream DestinationStream)
        {
            bool first = true;
            uint offset = 0;
            uint address = 0;
            foreach (IntelHexLine line in HexFile)
            {
                if (line is IntelHexDataLine)
                {
                    var dataLine = (IntelHexDataLine)line;
                    if (_trimStart && first)
                        offset = address + dataLine.Address;
                    first = false;

                    DestinationStream.Seek(address + dataLine.Address - offset, SeekOrigin.Begin);
                    dataLine.Data.Seek(0, SeekOrigin.Begin);
                    dataLine.Data.CopyTo(DestinationStream);
                }
                if (line is IntelHexExAddressLine)
                {
                    var addresLine = (IntelHexExAddressLine)line;
                    address = (uint)(addresLine.AddressExtension << 16);
                }
                if (line is IntelHexSegAddressLine)
                {
                    var addresLine = (IntelHexSegAddressLine)line;
                    address = addresLine.SegmentAddress;
                }
            }
        }
 public IntelHexFile Read(TextReader Reader)
 {
     var file = new IntelHexFile();
     string line;
     while ((line = Reader.ReadLine()) != null)
     {
         byte[] dat = GetBytes(line).ToArray();
         byte len = dat[0];
         var address = (ushort)(dat[1] << 8 | dat[2]);
         byte type = dat[3];
         byte checksum = dat.Last();
         byte[] data = dat.Skip(4).Take(dat.Length - 5).ToArray();
         switch (type)
         {
             case 0:
                 file.Add(new IntelHexDataLine(address, data));
                 break;
             case 1:
                 file.Add(new IntelHexEndLine());
                 break;
             case 2:
                 file.Add(new IntelHexSegAddressLine((uint)((data[0] << 8 | data[1]) << 4)));
                 break;
             case 4:
                 file.Add(new IntelHexExAddressLine((ushort)(data[0] << 8 | data[1])));
                 break;
         }
     }
     return file;
 }