Convert digital input and output decimal value to binary vector

`out = dec2binvec(dec)`

`out = dec2binvec(dec,bits)`

| A decimal value. |

| Number of bits used to represent the decimal number. |

| A logical array containing the binary vector. |

converts
the decimal value `out = dec2binvec(dec)`

`dec`

to an equivalent binary vector
and stores the result as a logical array in `out`

.

converts
the decimal value `out = dec2binvec(dec,bits)`

`dec`

to an equivalent binary vector
consisting of at least the number of bits specified by `bits`

.

To convert the decimal value 23 to a binvec value:

dec2binvec(23)

ans = 1 1 1 0 1

To convert the decimal value 23 to a binvec value using six bits:

dec2binvec(23,6)

ans = 1 1 1 0 1 0

To convert the decimal value 23 to a binvec value using four bits, then the result uses five bits. This is the minimum number of bits required to represent the number.

dec2binvec(23,4)

ans = 1 1 1 0 1

Was this topic helpful?