DLeftCountingBloomFilter { protected long getBits(byte[] input, long numBits, int pos) { long value = 0; long postBits = pos % 8; int i = pos/8; long start = postBits > numBits ? numBits : postBits; if (start != 0) { value = input[i++] & (0xFF >> (8 - start)); numBits -= start; } while (numBits >= 8) { value = (value << 8) | input[i++]; numBits -= 8; } if (numBits != 0) { long last = (input[i] >> (8 - numBits)); value = (value << numBits) | last; } return value; } DLeftCountingBloomFilter(int d, int b);   }
@Test public void test() throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance("SHA-1"); byte[] b = md.digest("testf".getBytes()); String hex = byteArrayToHexString(b); System.out.println("Byte size: " + b.length); System.out.println("Hex: " + hex); DLeftCountingBloomFilter filter = new DLeftCountingBloomFilter(8, 32); long bits = filter.getBits(b, 5, 0); System.out.println("Bits: " + bits); }