matlab中的 Decimal to Binary d = s; n = N; d = doubled; if nargin2 n=1; Need at least one digit even for 0 else if ~isnumericn ischarn ~isscalarn n0 errorMA
def decimal_to_binary(d, n=1): d = float(d) if not isinstance(n, (int, float)) or n < 0: raise ValueError('N must be a positive scalar numeric.') n = round(n)
f, e = math.frexp(max(d))
binary_str = ''
for i in range(1 - max(n, e), 1):
binary_str += str(int(d * 2**i) % 2)
return binary_str
原文地址: http://www.cveoy.top/t/topic/iZKW 著作权归作者所有。请勿转载和采集!