Java BitSet validateEncoded(BitSet encoded, int encodedBitLength)

Here you can find the source of validateEncoded(BitSet encoded, int encodedBitLength)

Description

validate Encoded

License

Open Source License

Declaration

private static boolean validateEncoded(BitSet encoded,
            int encodedBitLength) 

Method Source Code

//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;
    }
}

Related

  1. toString(BitSet bs)
  2. translateBitSetToProjIndx(BitSet projBitSet)
  3. unionAdd(BitSet newClique, int nNodes, LinkedList cliques)
  4. unpackInt(BitSet bs, int offset, int noOfBits)
  5. unsignedIntToLittleEndianBitSet(int i)
  6. validCookieNameOctets(BitSet validCookieValueOctets)