-1

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.

Community
  • 1
  • 1
yogupta
  • 188
  • 1
  • 3
  • 9
  • In Java, C, C++, the operator for XOR is `^` e.g. `a ^ b` – Peter Lawrey Nov 01 '16 at 16:14
  • I'm implementing the program for crc. assume the divisor is 10011 and dividend is 11010111110000. the remainder for this must be 10. if i perform XOR `^` on it, XOR will give the result as 11010111100011. – yogupta Nov 01 '16 at 16:24

1 Answers1

0

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.

mhery
  • 2,097
  • 4
  • 26
  • 35