Convert to binary.
516645
def _to_binary(val):
    """"""
    if isinstance(val, text_type):
        return val.encode('utf-8')
    assert isinstance(val, binary_type)
    return val
991784
def to_unit(value, unit='B'):
    """"""
    byte_array = ['B', 'KB', 'MB', 'GB', 'TB']

    if not isinstance(value, (int, float)):
        value = float(value)

    if unit in byte_array:
        result = value / 1024**byte_array.index(unit)
        return round(result, PRECISION), unit

    return value
5150
def parse(binary, **params):
    """"""
    encoding = params.get('charset', 'UTF-8')
    return json.loads(binary, encoding=encoding)
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
65607
def val_to_bin(edges, x):
    """"""
    ibin = np.digitize(np.array(x, ndmin=1), edges) - 1
    return ibin
783399
def binary(self):
    """"""
    dependencies = self.dependencies
    if len(dependencies) != 1:
      raise TargetDefinitionException(self, 'An app must define exactly one binary '
                                            'dependency, have: {}'.format(dependencies))
    binary = dependencies[0]
    if not isinstance(binary, PythonBinary):
      raise TargetDefinitionException(self, 'Expected binary dependency to be a python_binary '
                                            'target, found {}'.format(binary))
    return binary
729891
def as_bin(self):
        """"""
        f = io.BytesIO()
        self.stream(f)
        return f.getvalue()
1229983
def to_code(self, stacksize=None):
        """"""
        if stacksize is None:
            stacksize = self.compute_stacksize()
        bc = self.to_bytecode()
        return bc.to_code(stacksize=stacksize)
939939
def bin_to_int(string):
    """"""
    if isinstance(string, str):
        return struct.unpack("b", string)[0]
    else:
        return struct.unpack("b", bytes([string]))[0]
1247613
def log_binary(logger, message, **kwargs):
    """"""
    if logger.isEnabledFor(logging.DEBUG):
        output = ('{0}={1}'.format(k, binascii.hexlify(
            bytearray(v)).decode()) for k, v in sorted(kwargs.items()))
        logger.debug('%s (%s)', message, ', '.join(output))
519838
def dict_to_binary(val)
      saved_object_count = @written_object_count
      @written_object_count += 1

      #@object_refs += val.value.keys.size * 2

      keys_and_values = val.value.keys.map { |k| CFString.new(k).to_binary(self) }
      keys_and_values.concat(val.value.values.map { |v| v.to_binary(self) })

      bdata = Binary.type_bytes(0b1101,val.value.size) <<
        Binary.pack_int_array_with_size(object_ref_size(@object_refs), keys_and_values)

      @object_table[saved_object_count] = bdata
      return saved_object_count
    end
432641
def binary(self):
        
        if isinstance(self.value, bytes):
            length = len(self.value)
            if length > 4294967295:
                raise OutputException('uint32 overflow')
            elif self.bits != 8:
                return (
                    b_chr(_TAG_BIT_BINARY_EXT) +
                    struct.pack(b'>I', length) +
                    b_chr(self.bits) + self.value
                )
            else:
                return (
                    b_chr(_TAG_BINARY_EXT) +
                    struct.pack(b'>I', length) +
                    self.value
                )
        else:
            raise OutputException('unknown binary type')
593147
def to_bytes(s):
    '''
    '''
    if isinstance(s, six.binary_type):
        return s
    if isinstance(s, six.string_types):
        return s.encode('utf-8')
    raise TypeError('want string or bytes, got {}', type(s))
973095
private double convertToDouble(byte[] bin){
        ByteBuffer bb = ByteBuffer.wrap(bin);
        bb.order(ByteOrder.BIG_ENDIAN);
        if(bin.length < 4)
            return bb.getShort();
        else if(bin.length < 8)
            return bb.getInt();
        else
            return bb.getDouble();
    }
686140
function convertBinaryToBase36(binary)
{
	var result = '';
	for (var i = 0; i < 25; i++)
	{
		var c;
		if (typeof binary == 'string')
		{
			c = binary.charCodeAt(i) % 36;
		}
		else
		{
			c = binary[i] % 36;
		}
		if (c < 10)
		{
			result += String.fromCharCode(48 + c);
		}
		else
		{
			result += String.fromCharCode(87 + c);
		}
	}
	return result;
}
1166562
def read_binary(self, num, item_type='B'):
        """"""
        if 'B' in item_type:
            return self.read(num)

        if item_type[0] in ('@', '=', '<', '>', '!'):
            order = item_type[0]
            item_type = item_type[1:]
        else:
            order = '@'

        return list(self.read_struct(Struct(order + '{:d}'.format(int(num)) + item_type)))
301534
def ensure_binary(s, encoding='utf-8', errors='strict'):
    
    if isinstance(s, text_type):
        return s.encode(encoding, errors)
    elif isinstance(s, binary_type):
        return s
    else:
        raise TypeError("not expecting type '%s'" % type(s))