ApexLumia.Crc16Ccitt.ComputeChecksum C# (CSharp) Метод

ComputeChecksum() публичный Метод

public ComputeChecksum ( byte bytes ) : ushort
bytes byte
Результат ushort
        public ushort ComputeChecksum(byte[] bytes)
        {
            ushort crc = this.initialValue;
            for(int i = 0; i < bytes.Length; ++i) {
                crc = (ushort)((crc << 8) ^ table[((crc >> 8) ^ (0xff & bytes[i]))]);
            }
            return crc;
        }

Usage Example

Пример #1
0
        public bool compileSentence()
        {
            //CALLSIGN,SENTENCE_ID,TIME,LATITUDE,LONGITUDE,ALTITUDE,[CUSTOM, DATA, ..., ...]
            string _sentence;

            if (callsign.Length > 1)
            {
                _sentence = callsign.ToUpper();
            }
            else
            {
                return(false);
            }
            if (sentence_id >= 0)
            {
                _sentence += "," + sentence_id;
            }
            else
            {
                return(false);
            }
            _sentence += "," + System.DateTime.Now.ToString("HH:mm:ss");
            _sentence += "," + latitude;
            _sentence += "," + longitude;
            _sentence += "," + altitude;
            foreach (string item in sentenceData)
            {
                _sentence += "," + item;
            }

            Crc16Ccitt crc      = new Crc16Ccitt();
            string     checksum = crc.ComputeChecksum(System.Text.UTF8Encoding.UTF8.GetBytes(_sentence)).ToString("X");

            // $$$$$$CALLSIGN,SENTENCE_ID,TIME,LATITUDE,LONGITUDE,ALTITUDE,[CUSTOM, DATA, ..., ...]*XXXX
            if (checksum.Length == 4)
            {
                _wholeSentence = "$$" + _sentence + "*" + checksum;
            }
            else
            {
                return(false);
            }

            return(true);
        }
All Usage Examples Of ApexLumia.Crc16Ccitt::ComputeChecksum