MATLAB帮助文档解释:
function:
dec2bin Convert decimal integer to its binary representation
usage:
dec2bin(D) returns the binary representation of D as a character vector. D must be a non-negative integer. If D is greater than flintmax, dec2bin might not return an exact representation of D.
dec2bin(D,N) produces a binary representation with at least N bits.
函数功能:
把一个十进制数转换成一个字符串形式的二进制数。
语法:
dec2bin(D) 把十进制数D转换成二进制形式,并存在一个字符串中。
dec2bin(D,N) 把十进制数D转换成二进制形式,并存在一个字符串中。N指定二进制的位数,但是如果返回的二进制位数大于N,则以实际为准。
示例:
demo1:
dec2bin(5) 返回‘101’
demo2:
dec2bin(5,4) 返回‘0101’
demo3:
dec2bin(5,2) 返回‘101’