Trying to figure out how to check a checksum
Posted
by rross
on Stack Overflow
See other posts from Stack Overflow
or by rross
Published on 2010-05-19T15:54:46Z
Indexed on
2010/05/19
17:10 UTC
Read the original article
Hit count: 246
I'm trying to figure out how to check a checksum. My message looks like this:
38 0A 01 12 78 96 FE 00 F0 FB D0 FE F6
F6 being the checksum. I convert the preceding 12 sets in to binary and then add them together. Then attempt a bitwise operation to apply the 2s complement. I get a value of -1562, but I can't convert it back to hex to check if the value is correct. Can someone point me in the right direction?
my code:
string[] hexValue = {"38", "0A", "01", "12", "78", "96", "FE", "00", "F0", "FB", "D0", "FE"};
int totalValue = 0;
foreach(string item in hexValue)
{
totalValue += Int32.Parse(item, NumberStyles.HexNumber);
}
int bAfter2sC = ~totalValue + 1;
Console.Write("answer :" + bAfter2sC + "\n");
© Stack Overflow or respective owner