This example shows how to convert binary numbers to decimal integers. It highlights the difference between right- and left- most significant digit positioning.
b1 = [0 1 0 1 1];
b2 = [1 1 1 0];
Convert the two binary arrays to decimal by using the bi2de function. Assign the most significant digit is the leftmost element. The output of converting b1 corresponds to , and b2 corresponds to .
d1 = bi2de(b1,'left-msb')
d1 = 11
d2 = bi2de(b2,'left-msb')
d2 = 14
Assign the most significant digit is the rightmost element. The output of converting b1 corresponds to , and b2 corresponds to .
Decimal output, returned as an nonnegative
integer or row vector. If b
is a matrix, each row represents a
base-p number. In this case,
the output d is a column
vector in which each element is the decimal
representation of the corresponding row of
b.
If the input data type is
An integer data type and the value of
d can be contained in the
same integer data type as the input, the output
data type uses the same data type as the input.
Otherwise, the output data type is chosen to be
big enough to contain the decimal output.
double or logical data type, the output data
type is double.
single data type, the output data type is
single.
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.