Products & Services Solutions Academia Support User Community Company

Learn more about Communications Toolbox   

bi2de - Convert binary vectors to decimal numbers

Syntax

dbi2de(b)
d = bi2de(b,flg)
d = bi2de(b,p)
d = bi2de(b,p,flg)

Description

dbi2de(b) converts a binary row vector b to a nonnegative decimal integer. If b is a matrix, 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,flg) is the same as the syntax above, except that flg is a string that determines whether the first column of b contains the lowest-order or highest-order digits. Possible values for flg 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 2. The first column of b is the lowest base-p digit. If b is a matrix, 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,flg) is the same as the syntax above, except that flg is a string that determines whether the first column of b contains the lowest-order or highest-order digits. Possible values for flg 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 might vary because 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')

The output is

d =

   551

See Also

de2bi

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS