writeBits method

void writeBits(
  1. int value,
  2. int bits
)

Implementation

void writeBits(int value, int bits) {
  if (bits < getBitsNeeded(value.abs())) {
    throw Exception(
        "Value $value is too large for $bits bits. You would need ${getBitsNeeded(value.abs())} bits to write $value. (or write up to ${pow(2, bits) - 1}) bits");
  }

  allocateIfNeeded(bits);
  _buffer.setBits(_i(bits), bits, value);
}