若所求校验为两位ASCII码,LRC就是循环求和后,取256的模,取补码,即为所求校验码;若要四位就改变模值即可
用了两个textbox;
textBox1用于字符输入
textBox2用于处理后输出
button1用于响应
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace encoding
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string original = textBox1.Text; // 从广文本框读入原始数据
// 用于测试的数据 :A0030201C8EE
// 冒号为起始
// A0为设备地址
// 03为控制指令
// 02为数据长度 本测试程序只计算了第二位
// 01C8为数据
// EE为校验码
string[] buf = new string[original.Length];
for (int i = 1; i < original.Length; i++)