Here you can find the source of validateEncoded(BitSet encoded, int encodedBitLength)
private static boolean validateEncoded(BitSet encoded, int encodedBitLength)
//package com.java2s; //License from project: Open Source License import java.util.BitSet; public class Main { private static boolean validateEncoded(BitSet encoded, int encodedBitLength) { int errorSyndromeLength = (int) (Math.log(encodedBitLength) / Math .log(2)) + 1;//from www.j a v a2 s . c o m BitSet errorSyndrome = new BitSet(errorSyndromeLength); for (int bitmask = 1, j = 0; j < errorSyndromeLength; bitmask <<= 1, ++j) { int countOfBits = 0; for (int i = bitmask; i <= encodedBitLength; ++i) { if ((i & bitmask) != 0) { countOfBits += (encoded.get(encodedBitLength - i) ? 1 : 0); } } countOfBits %= 2; errorSyndrome.set(j, countOfBits != 0); } return errorSyndrome.length() == 0; } }