Wie konvertiere ich eine Zeichenfolge in das Motorola S3 -Datensatzformat in einem Bash -Skript?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie konvertiere ich eine Zeichenfolge in das Motorola S3 -Datensatzformat in einem Bash -Skript?

Post by Anonymous »

Ich bin neu, um das Skriptprogrammieren zu verprügeln und brauche Hilfe bei der Konvertierung einer Zeichenfolge in das Motorola S3 -Format. Ausgangszeichenfolge sollte "S30D0000000046312E3044312E304A" < /p>
Der äquivalente (funktionierende) C# -Code lautet wie folgt: < /p>

Code: Select all

    public static string GetSrec(string data) {

// get s-record type, number of bytes remaining, and address

string type = "S3";
byte numBytesRem = (byte)(4 + data.Length + 1);
uint address = 0;

// begin building s-record

string srec = type + numBytesRem.ToString("X2") + address.ToString("X8");

// insert data into s-record

foreach (char c in data) {
srec += ((byte)c).ToString("X2");
}

// calculate and append checksum to s-record

byte checksum = 0;
for (int i = 2; i < srec.Length; i += 2) {
checksum += Convert.ToByte(srec.Substring(i, 2), 16); // offset i, length 2, base 16
}
checksum = (byte)~checksum;
srec += checksum.ToString("X2");

// return s-record

return srec;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post