returns need bits from the input buffer
 == Format Notes
 bits are stored LSB to MSB
431173
def get_bits need
    val = @bit_bucket
    while @bit_count < need
      val |= (@input_buffer[@in_pos+=1] << @bit_count)
      @bit_count += 8
    end

    @bit_bucket = val >> need
    @bit_count -= need
    val & ((1 << need) - 1)
  end
731585
BitArray getUnalignedBitString() throws IOException {
        if (pos >= count)
            return null;
        /*
         * Just copy the data into an aligned, padded octet buffer,
         * and consume the rest of the buffer.
         */
        int len = available();
        int unusedBits = buf[pos] & 0xff;
        if (unusedBits > 7 ) {
            throw new IOException("Invalid value for unused bits: " + unusedBits);
        }
        byte[] bits = new byte[len - 1];
        // number of valid bits
        int length = (bits.length == 0) ? 0 : bits.length * 8 - unusedBits;

        System.arraycopy(buf, pos + 1, bits, 0, len - 1);

        BitArray bitArray = new BitArray(length, bits);
        pos = count;
        return bitArray;
    }
245637
def get_bits( self, count ):
        """"""
        result = 0
        for i in range( count ):
            if self.bits_remaining <= 0:
                self._fill_buffer()
            if self.bits_reverse:
                bit = (1 if (self.current_bits & (0x80 << 8*(self.bytes_to_cache-1))) else 0)
                self.current_bits <<= 1
                self.current_bits &= 0xff
            else:
                bit = (self.current_bits & 1)
                self.current_bits >>= 1

            self.bits_remaining -= 1

            if self.output_reverse:
                result <<= 1
                result |= bit
            else:
                result |= bit << i
        return result
712698
public static boolean[] getBits(final byte b) {
        final boolean[] res = new boolean[8];
        for (int i = 0; i < 8; i++) {
            res[7 - i] = (b & (1 << i)) != 0;
        }
        return res;
    }
487268
public BitArray getUnalignedBitString() throws IOException {
        if (buffer.read() != DerValue.tag_BitString)
            throw new IOException("DER input not a bit string");

        int length = getLength(buffer) - 1;

        /*
         * First byte = number of excess bits in the last octet of the
         * representation.
         */
        int validBits = length*8 - buffer.read();

        byte[] repn = new byte[length];

        if ((length != 0) && (buffer.read(repn) != length))
            throw new IOException("short read of DER bit string");
        return new BitArray(validBits, repn);
    }
619797
def bits_to_bytes(bits):
    
    if len(bits) % 8 != 0:
        raise Exception("num bits must be multiple of 8")

    res = ""

    for x in six.moves.range(0, len(bits), 8):
        byte_bits = bits[x:x+8]
        byte_val = int(''.join(map(str, byte_bits)), 2)
        res += chr(byte_val)

    return utils.binary(res)
806882
public int getAnalysisBits()
  {
    int bits = 0;
    
    if (m_exprs != null)
    {
      int n = m_exprs.length;

      for (int i = 0; i < n; i++)
      {
      	int bit = m_exprs[i].getAnalysisBits();
        bits |= bit;
      }
    }

    return bits;
  }
317427
def frombits(cls, bits='0'):
        """"""
        if len(bits) > cls._len:
            raise ValueError('too many bits %r' % (bits,))
        return cls.fromint(bits[::-1], 2)
1186740
function wstring(bits, s) {
      var charLength = bits / 8;
      var dataLength = s.length * charLength;
      var res = Buffer.alloc(xutil.padded_length(dataLength));
      debugger;
      var write = res[bufferWriteBits[bits]];
      res.fill(0);
      for (var i = 0; i < s.length; i++) write.call(res, s.charCodeAt(i), i * charLength);
      return res;
    }
1062307
def insert(self, bs, pos=None):
        
        bs = Bits(bs)
        if not bs.len:
            return self
        if bs is self:
            bs = self.__copy__()
        if pos is None:
            try:
                pos = self._pos
            except AttributeError:
                raise TypeError("insert require a bit position for this type.")
        if pos < 0:
            pos += self.len
        if not 0 <= pos <= self.len:
            raise ValueError("Invalid insert position.")
        self._insert(bs, pos)
844455
def bytes_to_bits(bytes_):
    
    res = []
    for x in bytes_:
        if not isinstance(x, int):
            x = ord(x)
        res += byte_to_bits(x)
    return res
792180
private static int getLengthBits(int version, int bitsA, int bitsB, int bitsC) {
		int lengthBits;

		if (version < 10)
			lengthBits = bitsA;
		else if (version < 27)
			lengthBits = bitsB;
		else
			lengthBits = bitsC;
		return lengthBits;
	}
1151657
def each_bit
      return enum_for(:each_bit) unless block_given?
      index = 0
      bitsize = self.bitsize
      @data.each_byte do |byte|
        loop do
          break if index == bitsize
          bit = (byte >> (7 - (index & 7))) & 1
          yield bit
          index += 1
          break if (index & 7) == 0
        end
      end
      return self
    end
1238529
public Bits toBits() {
    int peekBits = (int) Math.ceil(Math.log(max) / Math.log(2)) + 4;
    Bits startBits = Bits.divide(start, max, peekBits).padRight(peekBits);
    Bits endBits = Bits.divide(end(), max, peekBits).padRight(peekBits);
    for (int i = 0; i < peekBits; i++) {
      long a = startBits.range(0, i).toLong();
      long b = endBits.range(0, i).toLong();
      if (b - a > 1) {
        Bits bits = new Bits(a + 1, i);
        assert (Bits.ZERO.equals(bits.range(0, 1)));
        return bits.range(1);
      }
    }
    throw new RuntimeException();
  }
361497
private String getFormattedBytes(WsByteBuffer buff)
   {
          // Note we do not really want to trace the buffer since we are about to dump the bytes in the buffer in an FFDC anyway.
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "getFormattedBytes", null);

          int currentPosition = buff.position();
      int currentLimit = buff.limit();
      buff.rewind();

      try
      {
         // If the buffer is backed by an array, just get the bytes straight from the buffer
         if (buff.hasArray())
         {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "getFormattedBytes", null);
                return SibTr.formatBytes(buff.array(), buff.arrayOffset() + buff.position(), buff.remaining());
         }

         // Otherwise we need to make a copy of it
         byte[] dataArray = new byte[buff.remaining()];
         buff.get(dataArray);
         if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "getFormattedBytes", null);
         return SibTr.formatBytes(dataArray, 0, dataArray.length);
      }
      finally
      {
         buff.position(currentPosition);
         buff.limit(currentLimit);
      }

   }
188687
def getBytes(self) -> list:
        ''''''
        tmpList = []
        tmpList.extend(_FIRST_INDEX)
        # first append the high byte from the Flags and Length
        # high 4 bit: 0x7 then the bits 8-11(indexes) from _length
        length = self.length - 16
        tmpList.append((0x7 << 4) + (length >> 8))
        # Then append the lower 8 bits from _length
        tmpList.append(length & 0xFF)

        tmpList.extend(self._vector)
        tmpList.extend(self._cid)
        return tmpList
1152336
function writeBitField(setBits, bitIndex) {
	var bitLen = bitIndex.length;
	var blen = Math.ceil(bitLen / 8);
	var unused = blen * 8 - bitLen;
	var bits = Buffer.alloc(1 + blen); // zero-filled
	bits[0] = unused;
	for (var i = 0; i < bitLen; ++i) {
		var byteN = 1 + Math.floor(i / 8);
		var bit = 7 - (i % 8);
		var mask = 1 << bit;
		var name = bitIndex[i];
		if (name === undefined)
			continue;
		var bitVal = (setBits.indexOf(name) !== -1);
		if (bitVal) {
			bits[byteN] |= mask;
		}
	}
	return (bits);
}