Ejemplo n.º 1
0
 private byte getCheckDigit(List <byte> cmdCombined)
 {
     bool[] bits = BitConverterEx.GetBits(cmdCombined[0]);
     for (int j = 1; j < cmdCombined.Count; j++)
     {
         for (byte i = 0; i < 8; i++)
         {
             bits[i] ^= BitConverterEx.TestB(cmdCombined[j], i);
         }
     }
     return(BitConverterEx.ConvertToByte(bits));
 }
Ejemplo n.º 2
0
        private string getCheckDigit(string cmdCombined)
        {
            bool[] bits = BitConverterEx.GetBits((byte)cmdCombined[0]);
            for (int j = 1; j < cmdCombined.Length; j++)
            {
                for (byte i = 0; i < 8; i++)
                {
                    bits[i] ^= BitConverterEx.TestB(cmdCombined[j], i);
                }
            }
            int upperBit = 0;
            int lowerBit = 0;

            for (byte i = 0; i < 4; i++)
            {
                BitConverterEx.SetBit(ref lowerBit, i, bits[i]);
                BitConverterEx.SetBit(ref upperBit, i, bits[i + 4]);
            }
            return(string.Format("{0:x}{1:x}", upperBit, lowerBit));
        }