Returns index of sub in bytes.
        Raises ValueError if byte is not in bytes and TypeError if can't
        be converted bytes or its length is not 1.
187620
def index(self, sub, *args):
        '''
        
        '''
        if isinstance(sub, int):
            if len(args) == 0:
                start, end = 0, len(self)
            elif len(args) == 1:
                start = args[0]
            elif len(args) == 2:
                start, end = args
            else:
                raise TypeError('takes at most 3 arguments')
            return list(self)[start:end].index(sub)
        if not isinstance(sub, bytes):
            try:
                sub = self.__class__(sub)
            except (TypeError, ValueError):
                raise TypeError("can't convert sub to bytes")
        try:
            return super(newbytes, self).index(sub, *args)
        except ValueError:
            raise ValueError('substring not found')
309167
def str_byte_index(haystack, needle, offset = 0)

      result = nil
      mb_idx = haystack.index(needle, offset)

      unless mb_idx.nil?

        if mb_idx < 1
          result = 0
        else
          matched = haystack.slice(0..mb_idx)
          result  = matched.bytesize - matched[-1].bytesize
        end
      end

      result
    end
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
869952
def convert_bytes(value):
    
    n = np.rint(len(str(value))/4).astype(int)
    return value/(1024**n), sizes[n]
939441
def inv_sub_bytes(state):
    
    state = state.reshape(4, 32)
    return fcat(
        invsubword(state[0]),
        invsubword(state[1]),
        invsubword(state[2]),
        invsubword(state[3]),
    )
1293685
def length(self):
        
        if isinstance(self._value, int):
            return byte_len(self._value)
        if self._value is None:
            return 0
        return len(self._value)
755640
def index2qindexb(self, index):
        
        r = index // 0x10
        c = index % 0x10
        return self.index(r, c)
629496
private int bytesToInt(byte[] bytes)
    {
        int result = -1;
        if (bytes.length >= 4)
        {
            result = ((bytes[0]&0xff) << 24) +
                     ((bytes[1]&0xff) << 16) +
                     ((bytes[2]&0xff) << 8) +
                     (bytes[3]&0xff);
        }
        return result;
    }
1027285
def from_two_bytes(bytes):
    
    lsb, msb = bytes
    try:
        # Usually bytes have been converted to integers with ord already
        return msb << 7 | lsb
    except TypeError:
        # But add this for easy testing
        # One of them can be a string, or both
        try:
            lsb = ord(lsb)
        except TypeError:
            pass
        try:
            msb = ord(msb)
        except TypeError:
            pass
        return msb << 7 | lsb
569756
def GetSubkeyByIndex(self, index):
    
    if index < 0 or index >= self._pyregf_key.number_of_sub_keys:
      raise IndexError('Index out of bounds.')

    pyregf_key = self._pyregf_key.get_sub_key(index)
    if not pyregf_key:
      return None

    key_path = key_paths.JoinKeyPath([self._key_path, pyregf_key.name])
    return REGFWinRegistryKey(pyregf_key, key_path=key_path)
892186
def _get_slice_request_data(self, index):
        '''
        
        '''
        # Do a check on list indices for early error detection
        if not is_slice_or_dim_range(index):
            single_depth = self._get_single_depth(index)
            # Single value indices for first single_depth values
            if single_depth > 0:
                # We have integer request first
                subindicies = index[:single_depth]
                sublist = self
                # Use the other side of __getitem__ to grab subindices
                for sind in subindicies:
                    sublist = sublist[sind]
                # If we still have some index requests left or dimension
                # restrictions, then return a FixedListSubset
                if single_depth < len(index) or isinstance(sublist, FixedListSubset):
                    new_dim_ranges = self._combine_dimension_lists(self._dim_ranges, index)
                    return self.builder(sublist, *new_dim_ranges[single_depth:])
                # Otherwise our sublist is actually an element of the
                # original data, so just return it
                else:
                    return sublist
        new_dim_ranges = self._combine_dimension_lists(self._dim_ranges, index)
        return self.builder(self._data, *new_dim_ranges)
863027
def bytes_to_int(byte_array, big_endian=True, signed=False):
    
    if six.PY3:
        order = 'little'
        if big_endian:
            order = 'big'
        return int.from_bytes(byte_array, byteorder=order, signed=signed)
    else:
        length = len(byte_array)
        if length == 1:
            code = 'B'
        elif length == 2:
            code = 'H'
        elif length == 4:
            code = 'L'
        elif length == 8:
            code = 'Q'
        else:
            raise Exception("bytes_to_int : length of byte_array should be 1, 2, 4, or 8")
        if big_endian:
            code = '>'+code
        else:
            code = '<'+code

        if signed:
            code = code.lower()
        return struct.unpack(code, byte_array)[0]
1018419
public int indexOf(BinaryString subStr, int start) {
		ensureMaterialized();
		subStr.ensureMaterialized();
		if (subStr.sizeInBytes == 0) {
			return 0;
		}
		if (inFirstSegment()) {
			// position in byte
			int byteIdx = 0;
			// position is char
			int charIdx = 0;
			while (byteIdx < sizeInBytes && charIdx < start) {
				byteIdx += numBytesForFirstByte(getByteOneSegment(byteIdx));
				charIdx++;
			}
			do {
				if (byteIdx + subStr.sizeInBytes > sizeInBytes) {
					return -1;
				}
				if (SegmentsUtil.equals(segments, offset + byteIdx,
					subStr.segments, subStr.offset, subStr.sizeInBytes)) {
					return charIdx;
				}
				byteIdx += numBytesForFirstByte(getByteOneSegment(byteIdx));
				charIdx++;
			} while (byteIdx < sizeInBytes);

			return -1;
		} else {
			return indexOfSlow(subStr, start);
		}
	}
1302601
def index(self, i):
        
        if self.count(i) == 0:
            raise ValueError("{} is not in range".format(i))
        return (i - self._start) // self._step
231836
def follow_bytes(self, s, index):
        ""
        for ch in s:
            index = self.follow_char(int_from_byte(ch), index)
            if index is None:
                return None

        return index
706235
static public int byteIndexOf(byte[] bytes, byte target, int start_index) {

        int rc = -1; // simulate String.indexOf rc
        // stop when we are out of data or hit the target byte
        for (int index = start_index; index < bytes.length; index++) {
            if (target == bytes[index]) {
                rc = index;
                break;
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "byteIndexOf returning [" + rc + "]");
        }
        return rc;
    }
584806
def sub(self, b):
        
        new_bits = max(self.bits, b.bits)

        overflow = self._wrapped_overflow_sub(self, b)
        if overflow:
            return StridedInterval.top(self.bits)

        lb = self._modular_sub(self.lower_bound, b.upper_bound, new_bits)
        ub = self._modular_sub(self.upper_bound, b.lower_bound, new_bits)

        # Is it initialized?
        uninitialized = self.uninitialized or b.uninitialized

        # Take the GCD of two operands' strides
        stride = fractions.gcd(self.stride, b.stride)

        return StridedInterval(bits=new_bits, stride=stride, lower_bound=lb, upper_bound=ub,
                               uninitialized=uninitialized).normalize()