Communications Toolbox | ![]() ![]() |
Convert binary vectors to decimal numbers
Syntax
d = bi2de(b); d = bi2de(b,flag
) d = bi2de(b,p); d = bi2de(b,p,flag
);
Description
converts a binary row vector d
= bi2de(b)
b
to a nonnegative decimal integer. If b
is a matrix, then each row is interpreted separately as a binary number. In this case, the output d
is a column vector, each element of which is the decimal representation of the corresponding row of b
.
d = bi2de(b,
is the same as the syntax above, except that flag
)
flag
is a string that determines whether the first column of b
contains the lowest-order or highest-order digits. Possible values for flag
are 'right-msb
' and 'left-msb
'. The value 'right-msb
' produces the default behavior.
d = bi2de(b,p)
converts a base-p
row vector b to a nonnegative decimal integer , where p
is an integer greater than or equal to two. The first column of b
is the lowest base-p
digit. If b
is a matrix, then the output d
is a nonnegative decimal vector, each row of which is the decimal form of the corresponding row of b
.
d = bi2de(b,p,
is the same as the syntax above, except that flag
)
flag
is a string that determines whether the first column of b
contains the lowest-order or highest-order digits. Possible values for flag
are 'right-msb
' and 'left-msb
'. The value 'right-msb
' produces the default behavior.
Examples
The code below generates a matrix that contains binary representations of five random numbers between 0 and 15. It then converts all five numbers to decimal integers.
b = randint(5,4); % Generate a 5-by-4 random binary matrix. de = bi2de(b); disp(' Dec Binary') disp(' ----- -------------------') disp([de, b])
Sample output is below. Your results may vary since the numbers are random.
Dec Binary ----- ------------------- 13 1 0 1 1 7 1 1 1 0 15 1 1 1 1 4 0 0 1 0 9 1 0 0 1
The command below converts a base-five number into its decimal counterpart, using the leftmost base-five digit (4 in this case) as the most significant digit. The example reflects the fact that 4(53) + 2(52) +50 = 551.
d = bi2de([4 2 0 1],5,'left-msb') d = 551
See Also
de2bi
![]() | bchpoly | biterr | ![]() |