This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Convert decimal number to character vector representing binary number


str = dec2bin(d)
str = dec2bin(d,n)


str = dec2bin(d) returns the binary representation of d as a character vector. d must be a nonnegative integer. If d is greater than the value returned by flintmax, then dec2bin might not return an exact representation of d.

str = dec2bin(d,n) produces a binary representation with at least n bits.

The output of dec2bin is independent of the endian settings of the computer you are using.


Decimal 23 converts to binary 010111:

ans =

Extended Capabilities