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

example

````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

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.

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

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

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`.

## Examples

collapse all

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 = 5×1 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\left({8}^{3}\right)+2\left({8}^{2}\right)+7\left({8}^{1}\right)+1\left({8}^{0}\right)=2233$.

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