Quantcast

Documentation Center

  • Trial Software
  • Product Updates

dec2binvec

Convert digital input and output decimal value to binary vector

Syntax

out = dec2binvec(dec)
out = dec2binvec(dec,bits)

    Note:   You cannot use the legacy interface on 64–bit MATLAB®. See Session-Based Interface to acquire and generate data.

Arguments

dec

A decimal value. dec must be nonnegative.

bits

Number of bits used to represent the decimal number.

out

A logical array containing the binary vector.

Description

out = dec2binvec(dec) converts the decimal value dec to an equivalent binary vector and stores the result as a logical array in out.

out = dec2binvec(dec,bits) converts the decimal value dec to an equivalent binary vector consisting of at least the number of bits specified by bits.

Examples

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

More About

expand all

Tips

More About Binary Vectors

A binary vector (binvec) is constructed with the least significant bit (LSB) in the first column and the most significant bit (MSB) in the last column. For example, the decimal number 23 is written as the binvec value [1 1 1 0 1].

More About Specifying the Number of Bits

  • If bits is greater than the minimum number of bits required to represent the decimal value, then the result is padded with zeros.

  • If bits is less than the minimum number of bits required to represent the decimal value, then the minimum number of required bits is used.

  • If bits is not specified, then the minimum number of bits required to represent the number is used.

See Also

Was this topic helpful?