I have to extract the LRC From : "02 02 30 30 30 30 30 30 30 30 30 30 30 31 31 30 30 1c 35 32 33 1c 1c 2b 30 1c 39 34 36 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 1c 30 30 1c 1c 1c 1c 1c 1c 03" the corest answer must be : " 3B "
I tested the codes below but the result is wrong .
public static byte calculateLRC(byte[] bytes)
{
int LRC = 0;
for (int i = 0; i < bytes.Length; i++)
{
LRC -= bytes[i];
}
return (byte)LRC;
}
private static byte calculateLRC2(byte[] b)
{
byte lrc = 0x00;
for (int i = 0; i < b.Length; i++)
{
lrc = (byte)((lrc + b[i]) & 0xFF);
}
lrc = (byte)(((lrc ^ 0xff) + 2) & 0xFF);
return lrc;
}
public static char CalculateLRC3(string toEncode)
{
byte[] bytes = Encoding.ASCII.GetBytes(toEncode);
byte LRC = 0;
for (int i = 0; i < bytes.Length; i++)
{
LRC ^= bytes[i];
}
return Convert.ToChar(LRC);
}
public static byte calculateLRC4(byte[] bytes)
{
return bytes.Aggregate<byte, byte>(0, (x, y) => (byte)(x ^ y));
}
I'm waiting for your answer, thank you!!