# bi2de

(Not recommended) Convert Binary to Base-P

bi2de is not recommended. Instead, use the `bit2int` function. For more information, see Compatibility Considerations.

## 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 decimal integer. ```

example

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

## Examples

collapse all

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 $0\left({2}^{4}\right)+1\left({2}^{3}\right)+0\left({2}^{2}\right)+1\left({2}^{1}\right)+1\left({2}^{0}\right)=11$, and `b2` corresponds to $1\left({2}^{3}\right)+1\left({2}^{2}\right)+1\left({2}^{1}\right)+0\left({2}^{0}\right)=14$.

`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 $0\left({2}^{0}\right)+1\left({2}^{1}\right)+0\left({2}^{2}\right)+1\left({2}^{3}\right)+1\left({2}^{4}\right)=26$, and `b2` corresponds to $1\left({2}^{0}\right)+1\left({2}^{1}\right)+1\left({2}^{2}\right)+0\left({2}^{3}\right)=7$.

`d1 = bi2de(b1,'right-msb')`
```d1 = 26 ```
`d2 = bi2de(b2,'right-msb')`
```d2 = 7 ```

## Input Arguments

collapse all

Binary input, specified as a row vector or matrix of positive integer or logical values.

Note

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

Data Types: `double` | `single` | `logical` | `integer` | `fi`

MSB flag, specified as `'right-msb'` or `'left-msb'`.

• `'right-msb'` –– Indicates the right (or last) column of the binary input, b, as the most significant bit (or highest-order digit).

• `'left-msb'` –– Indicates the left (or first) column of the binary input, b, as the most significant bit (or highest-order digit).

Data Types: `char` | `string`

Base of the input `b`, specified as an integer greater than or equal to `2`.

Data Types: `double` | `single`

## Output Arguments

collapse all

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.

## Compatibility Considerations

expand all

Not recommended starting in R2021b