byte b = buffer.get(initialPos + position / 8);
int v = b < 0 ? b + 256 : b;
int left = 8 - position % 8;
int rc;
if (i <= left) {
rc = (v << (position % 8) & 0xFF) >> ((position % 8) + (left - i));
position += i;
} else {
int now = left;
int then = i - left;
rc = readBits(now);
rc = rc << then;
rc += readBits(then);
}
buffer.position(initialPos + (int) Math.ceil((double) position / 8));
return rc;