public static int getNullCount(final MemoryBuffer bitmapBuffer, int baseOffset, int valueCount) {
    // not null count + remainder
    int count = 0;
    final int sizeInBytes = (valueCount + 7) / 8;
    // If value count is not a multiple of 8, then calculate number of used bits in the last byte
    final int remainder = valueCount % 8;

    final int sizeInBytesMinus1 = sizeInBytes - 1;
    int bytesMinus1EndOffset = baseOffset + sizeInBytesMinus1;
    for (int i = baseOffset; i < bytesMinus1EndOffset; i++) {
      byte byteValue = bitmapBuffer.getByte(i);
      // byteValue & 0xFF: sets int to the (unsigned) 8 bits value resulting from
      // putting the 8 bits of value in the lowest 8 bits of int.
      count += Integer.bitCount(byteValue & 0xFF);
    }

    // handling with the last byte
    byte byteValue = bitmapBuffer.getByte(baseOffset + sizeInBytesMinus1);
    if (remainder != 0) {
      // making the remaining bits all 1s if it is not fully filled
      byte mask = (byte) (0xFF << remainder);
      byteValue = (byte) (byteValue | mask);
    }
    count += Integer.bitCount(byteValue & 0xFF);

    return 8 * sizeInBytes - count;
  }
@Test
  public void getNullCount() {
    int valueCount = 14;
    MemoryBuffer buffer = MemoryUtils.buffer(valueCount);
    buffer.putByte(0, (byte) 0b11000000);
    assertEquals(BitUtils.getNullCount(buffer, 0, 8), 6);
  }