Main Content

# decimalToBinaryVector

Convert decimal value to binary vector

## Syntax

``binVal = decimalToBinaryVector(decimalNumber)``
``binVal = decimalToBinaryVector(decimalNumber,numberOfBits)``
``binVal = decimalToBinaryVector(decimalNumber,numberOfBits,bitOrder)``
``binVal = decimalToBinaryVector(decimalNumber,[],bitOrder)``

## Description

This function is part of Data Acquisition Toolbox™, and converts decimal values to binary data represented by a vector of 1s and 0s. To convert to binary data as a character vector, you can use the MATLAB® function `dec2bin`.

````binVal = decimalToBinaryVector(decimalNumber)` converts a positive decimal number to a binary vector, represented using the minimum number of bits necessary.```

example

````binVal = decimalToBinaryVector(decimalNumber,numberOfBits)` converts a decimal number to a binary vector with the specified number of bits.```

example

````binVal = decimalToBinaryVector(decimalNumber,numberOfBits,bitOrder)` converts a decimal number to a binary vector with the specified number of bits in the specified bit ordering.```

example

````binVal = decimalToBinaryVector(decimalNumber,[],bitOrder)` converts a decimal number to a binary vector with default number of bits in the specified bit ordering.```

## Examples

collapse all

`binVal = decimalToBinaryVector(6)`
```binVal = 1 1 0```
`binVal = decimalToBinaryVector(0:4)`
```binVal = 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0```
`binVal = decimalToBinaryVector(6,8,'MSBFirst')`
```binVal = 0 0 0 0 0 1 1 0```
`binVal = decimalToBinaryVector(6,[],'LSBFirst')`
```binVal = 0 1 1```
`binVal = decimalToBinaryVector(0:4, 4,'LSBFirst')`
```binVal = 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 0 0 0 1 0```

## Input Arguments

collapse all

The number to convert to a binary vector specified as a positive integer scalar.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64`

The number of bits required to correctly represent the decimal. This is an optional argument. If you do not specify the number of bits, the number is represented using the minimum number of bits needed. By default minimum number of bits needed to represent the value is specified, unless you specify a value

Bit order for the binary vector representation, specified as a character vector or string. Accepted values are:

• `'MSBFirst'` — The first element of the binary vector is the most significant bit.

• `'LSBFirst'` — The first element of the binary vector is the least significant bit.

Data Types: `char` | `string`

## Output Arguments

collapse all

Binary value, returned as a double array of 1s and 0s.

## Version History

Introduced in R2012b