Return the position of the first bit set to 1 or 0 in a string.
544128
function bitpos(key, bit, start, end /* req */) {
  var req = typeof arguments[arguments.length - 1] === 'object'
    ? arguments[arguments.length - 1] : null
    , buf = this.getValueBuffer(key, req, true)
    , i
    , ind;

  if(buf === undefined) buf = new Buffer('');
  if(bit && !buf.length) return -1;

  // got start/end range
  if(arguments.length >= 3) {
    if(start < 0) start = buf.length + start;
    if(start < 0) start = 0;
    if(end < 0) end = buf.length + end;
    if(end < 0) end = 0;
    if(end > buf.length || end === undefined) end = buf.length;
  }else{
    start = 0;
    end = buf.length;
  }

  if(typeof start === 'object') start = 0;
  if(typeof end === 'object') end = buf.length;

  // get the range we are inspecting
  buf = buf.slice(start, end + 1);

  function getBitPos(bit, byte, index) {
    var mask = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01]
      , i;
    for(i = 0;i < mask.length;i++) {
      if(bit && (byte & mask[i]) || !bit && !(byte & mask[i])) {
        return index + i;
      }
    }
    return -1;
  }

  for(i = 0;i < buf.length;i++) {
    ind = getBitPos(bit, buf[i], (start + i) * 8);
    if(~ind) return ind;
  }

  // looking for clear bit, but all bits set
  if(!bit) return i * 8;

  return -1;
}
512762
public int first() {
        int val;
        int i;

        for (i = 0; i < data.length; i++) {
            if (data[i] != 0) {
                val = data[i];
                i <<= SHIFT;
                while ((val & 1) == 0) {
                    val >>>= 1;
                    i++;
                }
                return i;
            }
        }
        return -1;
    }
10024
long nextSetBit(long index) {
		// Depends on the ghost bits being clear!
		assert index >= 0 && index < numBits : "index=" + index + ", numBits=" + numBits;
		int i = (int) (index >> 6);
		long word = bits[i] >> index; // skip all the bits to the right of index

		if (word != 0) {
			return index + Long.numberOfTrailingZeros(word);
		}

		while (++i < numWords) {
			word = bits[i];
			if (word != 0) {
				return (i << 6) + Long.numberOfTrailingZeros(word);
			}
		}

		return -1;
	}
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
1112312
def changed_bit_pos(a, b):
    
    c = a ^ b
    n = 0
    while c > 0:
        if c & 1 == 1:
            return n
        c >>= 1
        n += 1
    return None
1087140
private int findValue(String s) {

        for (int i = 0; i < values.size(); i++) {
            if (s.equals(values.elementAt(i))) {
                return i;
            }    // end of if (s.equals(values.elementAt(i)))
        }        // end of for (int i=0; i<values.size(); i++)

        return -1;
    }
466831
def _readuintbe(self, length, start):
        """"""
        if length % 8:
            raise InterpretError("Big-endian integers must be whole-byte. "
                                 "Length = {0} bits.", length)
        return self._readuint(length, start)
281227
public static int getNumSetBits(ByteBuffer bfBuffer, int start)
  {
    ByteBuffer view = bfBuffer.duplicate().order(ByteOrder.BIG_ENDIAN);
    view.position(start);
    int numLongs = view.getInt(1 + start);
    int setBits = 0;
    for (int i = 0, pos = START_OF_SERIALIZED_LONGS + start; i < numLongs; i++, pos += Long.BYTES) {
      setBits += Long.bitCount(view.getLong(pos));
    }
    return setBits;
  }
124818
def getbit(self, key, offset):
        
        key = self._encode(key)
        index, bits, mask = self._get_bits_and_offset(key, offset)

        if index >= len(bits):
            return 0

        return 1 if (bits[index] & mask) else 0
1006031
static int getHexDigit(String s, int position) {
        int value = Character.digit(s.charAt(position), 16);
        if (value <= -1 || value >= 16) {
            throw new AssertionError("Unexpected failure of digit conversion of " +
                                     s.charAt(position));
        }
        return value;
    }
90301
function(str, num) {
    if (isUndefined(num)) num = 1;
    var start = str.length - num < 0 ? 0 : str.length - num;
    return str.substr(start);
  }
1185712
def get_char(self, offset=0):
        """"""
        if not self.has_space(offset=offset):
            return ''

        return self.string[self.pos + offset]
308549
def getNodePosition(cls, start, height=None) -> int:
        
        pwr = highest_bit_set(start) - 1
        height = height or pwr
        if count_bits_set(start) == 1:
            adj = height - pwr
            return start - 1 + adj
        else:
            c = pow(2, pwr)
            return cls.getNodePosition(c, pwr) + \
                cls.getNodePosition(start - c, height)
929179
def first_digits(s, default=0):
    
    s = re.split(r'[^0-9]+', str(s).strip().lstrip('+-' + charlist.whitespace))
    if len(s) and len(s[0]):
        return int(s[0])
    return default
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]
991645
def _get_boolean(data, position, dummy0, dummy1):
    """"""
    end = position + 1
    return data[position:end] == b"\x01", end
520044
def _get_c_string(data, position):
    """"""
    end = data.index(b"\x00", position)
    return _utf_8_decode(data[position:end], None, True)[0], end + 1