The last one in the communication protocol is the check digit.
Adopt BCC(Xor check) method
How do you explain this?
is to convert a 16 binary string into byte[] data, then take it out for an XOR and then return the value and check the comparison to see if it's right
For example:
232301fe313233343536373839303132333435363701001e0f01021226270001383938363032623531333136353033393731363001009e
The last one is 9E decimal for 158
Then we'll intercept the front part of 9E.
232301fe313233343536373839303132333435363701001e0f0102122627000138393836303262353133313635303339373136300100
Incoming method
<summary>
BCC and checksum code
</summary>
<param name= "Data" > packets that need to be validated </param>
<returns></returns>
Public byte Get_checkxor (byte[] data)
{
byte Checkcode = 0;
int len = data. Length;
for (int i = 0; i < len; i++)
{
Checkcode ^= Data[i];
}
return checkcode;
}
Return the same as the result is 158
If you haven't read it yet, we'll go back to 16.
<summary>
BCC and checksum code return 16 binary
</summary>
<param name= "Data" > packets that need to be validated </param>
<returns></returns>
public string Getbccxorcode (byte[] data)
{
byte Checkcode = 0;
int len = data. Length;
for (int i = 0; i < len; i++)
{
Checkcode ^= Data[i];
}
Return convert.tostring (Checkcode, 16). ToUpper ();
}
Return 9E
Learned a morning decided to share under the hope can help to the newly contacted classmates
C # bcc XOR checksum