| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- namespace ClassFile
- {
- class BaseUtil
- {
- /// <summary>
- /// 获取LRC
- /// </summary>
- /// <param name="SQL"></param>
- public static string getLRC(string SENDMESSAGE)
- {
- string message = SENDMESSAGE.Trim();
- if (message.Length % 2 != 0)
- {
- message = message + "0";
- }
- int LRC = 0x0;
- for (int i = 0; i < message.Length; i = i + 2)
- {
- int inside = int.Parse(message.Substring(i, 1).ToString() + message.Substring(i + 1, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
- LRC += inside;
- }
- string _LRC = string.Format("{0:X2}", LRC);
- string LRCre = "";
- for (int i = 0; i < _LRC.Length; i++)
- {
- int index;
- index = 0xF - int.Parse(_LRC.Substring(i, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
- LRCre += string.Format("{0:X}", index);
- }
- LRCre = string.Format("{0:X}", int.Parse(LRCre, System.Globalization.NumberStyles.HexNumber) + 1);
- return LRCre;
- }
- public static string ASCIIToString(string ASCII)
- {
- string ReturnStr = "";
- ASCII = ASCII.Replace(" ", "").Replace("3A", "").Replace("0D", "").Replace("0A", "");
- System.Console.WriteLine(ASCII);
- for (int i = 0; i < ASCII.Length; i = i + 2)
- {
- if (i + 2 < ASCII.Length)
- {
- switch (ASCII.Substring(i, 2))
- {
- case "30":
- ReturnStr += "0";
- break;
- case "31":
- ReturnStr += "1";
- break;
- case "32":
- ReturnStr += "2";
- break;
- case "33":
- ReturnStr += "3";
- break;
- case "34":
- ReturnStr += "4";
- break;
- case "35":
- ReturnStr += "5";
- break;
- case "36":
- ReturnStr += "6";
- break;
- case "37":
- ReturnStr += "7";
- break;
- case "38":
- ReturnStr += "8";
- break;
- case "39":
- ReturnStr += "9";
- break;
- case "41":
- ReturnStr += "A";
- break;
- case "42":
- ReturnStr += "B";
- break;
- case "43":
- ReturnStr += "C";
- break;
- case "44":
- ReturnStr += "D";
- break;
- case "45":
- ReturnStr += "E";
- break;
- case "46":
- ReturnStr += "F";
- break;
- default:
- break;
- }
- }
- }
- return ReturnStr;
- }
- }
- }
|