INNER CODE UNIT · Kotlin

BitBuffer

pedroSG94/RootEncoder · common/src/main/java/com/pedro/common/BitBuffer.kt:26

class BitBuffer(val buffer: ByteBuffer) {
  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

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…