INNER CODE UNIT · Kotlin
bufferPosition
pedroSG94/RootEncoder · common/src/main/java/com/pedro/common/BitBuffer.kt:27
var bufferPosition = buffer.position() * Byte.SIZE_BITS
private set
private val bufferEnd = buffer.limit() * Byte.SIZE_BITS
val bitRemaining: Int
get() = bufferEnd - bufferPosition
val remaining: Int
get() = ceil(bitRemaining.toDouble() / Byte.SIZE_BITS).toInt()
private fun getBits(size: Int): Long {
var result = 0L
for (i in 0 until size) {
val bitPosition = bufferPosition + i
val currentIndex = bitPosition / 8
val currentBit = bitPosition % 8
val bitValue = (buffer[currentIndex].toInt() ushr 7 - currentBit) and 0x01
result = (result shl 1) or bitValue.toLong()