there's a similar question [question]: How do you compute the XOR Remainder used in CRC?. I know the method which is explained in the above question.
the problem is how do I implement it in java.
there's a similar question [question]: How do you compute the XOR Remainder used in CRC?. I know the method which is explained in the above question.
the problem is how do I implement it in java.
I am implementing a CRC
simulator too, and I computed it like this:
public static String excludeFirstZeros(String string){
int i = 0;
for (; i < string.length(); i++){
if (string.charAt(i) == '1')
break;
}
return string.substring(i);
}
public static String sumBinsCRC(String binary, String generator) {
String partial = new String();
int i;
binary = excludeFirstZeros(binary);
for (i = 0; i < generator.length(); i++) {
partial = binary.charAt(i) == generator.charAt(i)?
partial.concat("0") : partial.concat("1");
}
partial = partial.concat(binary.substring(i));
return partial;
}
I have all code here, but I think you just want this part.