returns integer i after checking that it fits in the given number of bits.
552905
def int_subtype(i, bits, signed) :
        ""
        if not isinstance(i, int) :
            raise TypeError("value is not int: %s" % repr(i))
        #end if
        if signed :
            lo = - 1 << bits - 1
            hi = (1 << bits - 1) - 1
        else :
            lo = 0
            hi = (1 << bits) - 1
        #end if
        if i < lo or i > hi :
            raise ValueError \
              (
                "%d not in range of %s %d-bit value" % (i, ("unsigned", "signed")[signed], bits)
              )
        #end if
        return \
            i
11819
def _readintbe(self, length, start):
        """"""
        if length % 8:
            raise InterpretError("Big-endian integers must be whole-byte. "
                                 "Length = {0} bits.", length)
        return self._readint(length, start)
86032
public static int getVIntSize(long i) {
        if (i >= -112 && i <= 127) {
            return 1;
        }

        if (i < 0) {
            i ^= -1L; // take one's complement'
        }
        // find the number of bytes with non-leading zeros
        int dataBits = Long.SIZE - Long.numberOfLeadingZeros(i);
        // find the number of data bytes + length byte
        return (dataBits + 7) / 8 + 1;
    }
106728
def _readint(self, length, start):
        """"""
        ui = self._readuint(length, start)
        if not ui >> (length - 1):
            # Top bit not set, number is positive
            return ui
        # Top bit is set, so number is negative
        tmp = (~(ui - 1)) & ((1 << length) - 1)
        return -tmp
382964
public static Collection<Integer> ofUnsetBits(long i) {
    	final Collection<Integer> c = new LinkedList<Integer>();
        int k = 0;
        while (i != 0) {
            if ((i & 1L) == 0) {
                c.add(k);
            }
            k++;
            i >>>= 1;
        }
        return c;
    }
315615
public int nextSetBit(final int i) {
    int x = i >> 6;
    long w = bitmap[x];
    w >>>= i;
    if (w != 0) {
      return i + numberOfTrailingZeros(w);
    }
    for (++x; x < bitmap.length; ++x) {
      if (bitmap[x] != 0) {
        return x * 64 + numberOfTrailingZeros(bitmap[x]);
      }
    }
    return -1;
  }
934813
public int nextClearBit(final int i) {
    int x = i >> 6; // i / 64 with sign extension
    long w = ~bitmap.get(x);
    w >>>= i;
    if (w != 0) {
      return i + numberOfTrailingZeros(w);
    }
    int length = bitmap.limit();
    for (++x; x < length; ++x) {
      long map = ~bitmap.get(x);
      if (map != 0L) {
        return x * 64 + numberOfTrailingZeros(map);
      }
    }
    return MAX_CAPACITY;
  }
208784
def inttoDER(a):
    '''
    
    '''

    o = dechex(a,1)
    if int(o[:2],16) > 127:
        o = '00' + o
    olen = dechex(len(o)//2,1)
    return '02' + olen + o
428243
public int readRawUInt(int bits) throws IOException {
        int val = 0;
        for (int i = 0; i < bits; i++) {
            val = readBitToInt(val);
        }
        return val;
    }
867556
def _idx_to_bits(self, i):
    """"""
    bits = bin(i)[2:].zfill(self.nb_hyperplanes)  # Pad the bits str with 0
    return [-1.0 if b == "0" else 1.0 for b in bits]
743459
public static int readInt(DataInput in) throws IOException {
        byte len=in.readByte();
        if(len == 0)
            return 0;
        return makeInt(in, len);
    }
50589
private int integerDigits(double d) {
    double value = Math.abs(d);
    if(value < 10) {
      return 1;
    }
    return (int) FastMath.log10(value) + 1;
  }
773232
def _readuint(self, length, start):
        """"""
        if not length:
            raise InterpretError("Cannot interpret a zero length bitstring "
                                           "as an integer.")
        offset = self._offset
        startbyte = (start + offset) // 8
        endbyte = (start + offset + length - 1) // 8

        b = binascii.hexlify(bytes(self._datastore.getbyteslice(startbyte, endbyte + 1)))
        assert b
        i = int(b, 16)
        final_bits = 8 - ((start + offset + length) % 8)
        if final_bits != 8:
            i >>= final_bits
        i &= (1 << length) - 1
        return i
612540
static protected int getPadBits(
        int bitString)
    {
        int val = 0;
        for (int i = 3; i >= 0; i--)
        {
            //
            // this may look a little odd, but if it isn't done like this pre jdk1.2
            // JVM's break!
            //
            if (i != 0)
            {
                if ((bitString >> (i * 8)) != 0)
                {
                    val = (bitString >> (i * 8)) & 0xFF;
                    break;
                }
            }
            else
            {
                if (bitString != 0)
                {
                    val = bitString & 0xFF;
                    break;
                }
            }
        }

        if (val == 0)
        {
            return 7;
        }


        int bits = 1;

        while (((val <<= 1) & 0xFF) != 0)
        {
            bits++;
        }

        return 8 - bits;
    }
423703
public int readInt()
        throws IOException
    {
        int tag = is.read();

        if (tag != 'I')
            throw expect("integer", tag);

        int b32 = is.read();
        int b24 = is.read();
        int b16 = is.read();
        int b8 = is.read();

        return (b32 << 24) + (b24 << 16) + (b16 << 8) + b8;
    }
340042
def fromints(cls, ints):
        """"""
        return cls.frombitsets(map(cls.BitSet.fromint, ints))
154424
public int read1Bit() throws IOException {
        if (nBit == 8) {
            advance();
            if (curByte == -1) {
                return -1;
            }
        }
        int res = (curByte >> (7 - nBit)) & 1;
        nBit++;

        debugBits.append(res == 0 ? '0' : '1');
        ++bitsRead;

        return res;
    }