i have wrote a method that should calculate Fletcher checksum for a binary string. i used the answers provided in this question . here is the complete code:
String str = "101010100011001111001111";
int[] C = new int[2];
int indx = 0;
for (int i = 0; i < str.length()/8; i++){
int tmp = Integer.parseInt(str.substring(indx, indx+8),2);
C[0] = (C[0] + (tmp & 0xFF)) % 255;
C[1] = (C[1] + C[0]) % 255;
indx += 8;
}
System.out.println(C[0]);
System.out.println(C[1]);
System.out.println((C[1] << 8) | C[0]);
the results that i am getting are:
173
54
13997
based on this article the final result should be 0 if the checksum performed correctly, and as you can see it is not. can any one help me understand where the problem might be? i appreciate you help. thank you.