build a function that takes in some bytes, parses them as an unsigned int, then scales the returned value between the minimum and maximum values provided, then returns an object with min_{{key}}, max_{{key}}, and {{key}} values.
352551
function (actualValueKey, options) {
  return function (bytes) {
    var result = {};

    result['min_' + actualValueKey] = options.min_actual || 0;
    result['max_' + actualValueKey] = options.max_actual;
    result[actualValueKey] = misc.scaleValue(misc.bufferToInt(bytes), options);

    return result;
  };
}
640821
def _bottleneck_reduce(cls, func):
        

        def wrapped_func(self, **kwargs):
            from .dataarray import DataArray

            # bottleneck doesn't allow min_count to be 0, although it should
            # work the same as if min_count = 1
            if self.min_periods is not None and self.min_periods == 0:
                min_count = 1
            else:
                min_count = self.min_periods

            axis = self.obj.get_axis_num(self.dim)

            padded = self.obj.variable
            if self.center:
                if (LooseVersion(np.__version__) < LooseVersion('1.13') and
                        self.obj.dtype.kind == 'b'):
                    # with numpy < 1.13 bottleneck cannot handle np.nan-Boolean
                    # mixed array correctly. We cast boolean array to float.
                    padded = padded.astype(float)

                if isinstance(padded.data, dask_array_type):
                    # Workaround to make the padded chunk size is larger than
                    # self.window-1
                    shift = - (self.window + 1) // 2
                    offset = (self.window - 1) // 2
                    valid = (slice(None), ) * axis + (
                        slice(offset, offset + self.obj.shape[axis]), )
                else:
                    shift = (-self.window // 2) + 1
                    valid = (slice(None), ) * axis + (slice(-shift, None), )
                padded = padded.pad_with_fill_value({self.dim: (0, -shift)})

            if isinstance(padded.data, dask_array_type):
                values = dask_rolling_wrapper(func, padded,
                                              window=self.window,
                                              min_count=min_count,
                                              axis=axis)
            else:
                values = func(padded.data, window=self.window,
                              min_count=min_count, axis=axis)

            if self.center:
                values = values[valid]
            result = DataArray(values, self.obj.coords)

            return result
        return wrapped_func
740740
public static int toInt(byte[] bytes ) {
    int result = 0;
    for (int i = 0; i < 4; i++) {
      result = (result << 8) - Byte.MIN_VALUE + (int)bytes[i];
    }

    return result;
  }
1223045
def convert_ints_to_bytes(in_ints, num):
    """"""
    out_bytes= b""
    for val in in_ints:
        out_bytes+=struct.pack(mmtf.utils.constants.NUM_DICT[num], val)
    return out_bytes
441340
function( num, signed ) {
		var n = new Buffer(2);
		if (SAFE) { if (signed) {
			if (num < INT16_MIN) 
				throw new Errors.PackError('Packing integer bigger than 16-bits ('+num+')!');
			else if (num > INT16_MAX) 
				throw new Errors.PackError('Packing integer bigger than 16-bits ('+num+')!');
		} else {
			if (num < 0) 
				throw new Errors.PackError('Packing negative integer on unsigned 16-bit ('+num+')!');
			else if (num > UINT16_MAX) 
				throw new Errors.PackError('Packing integer bigger than 16-bits ('+num+')!');
		} }
		if (signed) packViewI16[0] = num;
		else packViewU16[0] = num;
		for (var i=0; i<2; ++i) n[i]=packViewU8[i];
		return n;
	}
774087
def _range(self, memory, addr, **kwargs):
        
        return (self._min(memory, addr, **kwargs), self._max(memory, addr, **kwargs))
4070
function readInteger(width, reader) {
    return function (start, cb) {
      var i = Math.floor(start/block_size)
      var _i = start%block_size

      //if the UInt32BE aligns with in a block
      //read directly and it's 3x faster.
      if(_i < block_size - width)
        get(i, function (err, block) {
          if(err) return cb(err)
          var value = reader(block, start%block_size)
          cb(null, value)
        })
      //but handle overlapping reads this easier way
      //instead of messing around with bitwise ops
      else
        read(start, start+width, function (err, buf, bytes_read) {
          if(err) return cb(err)
          var value = reader(buf, 0);
          cb(isNaN(value) ? new Error('Number is too large') : null, value)
        })
    }
  }
128621
function fromString(str, unsigned, radix) {
    if (str.length === 0)
        throw Error('empty string');
    if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
        return ZERO;
    if (typeof unsigned === 'number') {
        // For goog.math.long compatibility
        radix = unsigned,
        unsigned = false;
    } else {
        unsigned = !! unsigned;
    }
    radix = radix || 10;
    if (radix < 2 || 36 < radix)
        throw RangeError('radix');

    var p;
    if ((p = str.indexOf('-')) > 0)
        throw Error('interior hyphen');
    else if (p === 0) {
        return fromString(str.substring(1), unsigned, radix).neg();
    }

    // Do several (8) digits each time through the loop, so as to
    // minimize the calls to the very expensive emulated div.
    var radixToPower = fromNumber(pow_dbl(radix, 8));

    var result = ZERO;
    for (var i = 0; i < str.length; i += 8) {
        var size = Math.min(8, str.length - i),
            value = parseInt(str.substring(i, i + size), radix);
        if (size < 8) {
            var power = fromNumber(pow_dbl(radix, size));
            result = result.mul(power).add(fromNumber(value));
        } else {
            result = result.mul(radixToPower);
            result = result.add(fromNumber(value));
        }
    }
    result.unsigned = unsigned;
    return result;
}
694511
def int_to_bytes(val, bit=32, signed=False, big_endian=True):
    
    val = int(val) #ensure it is an int

    if six.PY3:
        order = 'little'
        if big_endian:
            order = 'big'
        return val.to_bytes(length=bit//8, byteorder=order, signed=signed)

    if bit == 8:
        code = 'B'
    elif bit == 16:
        code = 'H'
    elif bit == 32:
        code = 'I'
    elif bit == 64:
        code = 'Q'
    else:
        raise Exception("int_to_bytes : size parameter value should be 8, 16, 32, or 64")

    if big_endian:
        code = '>'+code
    else:
        code = '<'+code

    if signed or val < 0:
        code = code.lower()

    return struct.pack(code, val)
1228763
async function(min, max) {
    if (max.cmp(min) <= 0) {
      throw new Error('Illegal parameter value: max <= min');
    }

    const modulus = max.sub(min);
    const bytes = modulus.byteLength();

    // Using a while loop is necessary to avoid bias introduced by the mod operation.
    // However, we request 64 extra random bits so that the bias is negligible.
    // Section B.1.1 here: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
    const r = new BN(await this.getRandomBytes(bytes + 8));
    return r.mod(modulus).add(min);
  }
752534
def int_to_var_bytes(x):
    
    if x < 253:
        return intbytes.to_bytes(x, 1)
    elif x < 65536:
        return bytearray([253]) + intbytes.to_bytes(x, 2)[::-1]
    elif x < 4294967296:
        return bytearray([254]) + intbytes.to_bytes(x, 4)[::-1]
    else:
        return bytearray([255]) + intbytes.to_bytes(x, 8)[::-1]
510006
public static int putBigDecimal(byte[] bytes, int offset, BigDecimal val) {
    if (bytes == null) {
      return offset;
    }

    byte[] valueBytes = val.unscaledValue().toByteArray();
    byte[] result = new byte[valueBytes.length + SIZEOF_INT];
    offset = putInt(result, offset, val.scale());
    return putBytes(result, offset, valueBytes, 0, valueBytes.length);
  }
1302760
def normalize(value):
    
    if value and isinstance(value, bytes):
        value = value.decode('utf-8')
    return value
207130
function minValue(bound, formatError) {
        'use strict';
        return function (value) {
            if (value || !isNaN(parseFloat(value))) {
                var intValue = Number(value);
                if (!isNaN(intValue) && intValue < bound) {
                    return formatError(intValue);
                }
            }
            return '';
        };
    }
710140
private Object[] buildFromRange(int offset, int keyLength, boolean isLeaf, boolean isExtra)
    {
        // if keyLength is 0, we didn't copy anything from the original, which means we didn't
        // modify any of the range owned by it, so can simply return it as is
        if (keyLength == 0)
            return copyFrom;

        Object[] a;
        if (isLeaf)
        {
            a = new Object[keyLength + (keyLength & 1)];
            System.arraycopy(buildKeys, offset, a, 0, keyLength);
        }
        else
        {
            a = new Object[1 + (keyLength * 2)];
            System.arraycopy(buildKeys, offset, a, 0, keyLength);
            System.arraycopy(buildChildren, offset, a, keyLength, keyLength + 1);
        }
        if (isExtra)
            updateFunction.allocated(ObjectSizes.sizeOfArray(a));
        else if (a.length != copyFrom.length)
            updateFunction.allocated(ObjectSizes.sizeOfArray(a) -
                                     (copyFrom.length == 0 ? 0 : ObjectSizes.sizeOfArray(copyFrom)));
        return a;
    }
209177
def parse_byte_range(byte_range, min_byte=0, max_byte=sys.maxint):
    

    if not byte_range:
        return min_byte, max_byte

    begin = byte_range[0] or min_byte
    end = byte_range[1] or max_byte

    if end < begin:
        raise ValueError("End before begin")

    if begin < min_byte:
        raise ValueError("Begin smaller than min")

    if end > max_byte:
        raise ValueError("End larger than max")

    return begin, end
100115
def _uint2objs(ftype, num, length=None):
    """"""
    if num == 0:
        objs = [ftype.box(0)]
    else:
        _num = num
        objs = list()
        while _num != 0:
            objs.append(ftype.box(_num & 1))
            _num >>= 1

    if length:
        if length < len(objs):
            fstr = "overflow: num = {} requires length >= {}, got length = {}"
            raise ValueError(fstr.format(num, len(objs), length))
        else:
            while len(objs) < length:
                objs.append(ftype.box(0))

    return objs