Documentation

bi2de

Convert binary vectors to decimal numbers

Syntax

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

Description

d =bi2de(b) converts a binary row vector b to a nonnegative decimal integer.

d = bi2de(b,flg) converts a binary row vector to a decimal integer, where flg determines the position of the most significant digit.

d = bi2de(b,p) converts a base-p row vector b to a nonnegative decimal integer.

d = bi2de(b,p,flg) converts a base-p row vector to a decimal integer, where flg determines the position of the most significant digit.

Input Arguments

collapse all

b — Binary inputrow vector | matrix

Binary input specified as a row vector or matrix.

Example: [0 1 0]

Example: [1 0 0; 1 0 1]

    Note:   b must represent an integer less than or equal to 252.

flg — MSB flag'right-msb' | 'left-msb'

String that determines whether the first column corresponds to the lowest-order or highest-order digit. If omitted, bi2de assumes 'right-msb'.

p — Basepositive integer scalar

The base of the row vector that is converted to a decimal. Specify as a positive integer greater than or equal to 2.

Example: 4

Output Arguments

collapse all

d — Decimal outputscalar | vector

Decimal output converted from a base-p row vector b. Elements of d are nonnegative integers. 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.

Convert Binary Numbers to Decimals

Generate a matrix that contains binary representations of five random numbers between 0 and 15. Convert the binary numbers to decimal integers.

b = randi([0 1],5,4);
d = bi2de(b)
d =

     1
     5
    14
    11
    15

Convert a base-8 number to its decimal equivalent. Assign the most significant digit to the leftmost position. The output corresponds to $4(8^3)+2(8^2)+7(8^1)+1(8^0)=2233$.

d = bi2de([4 2 7 1],8,'left-msb')
d =

        2233

See Also

Introduced before R2006a

Was this topic helpful?