Data Acquisition Toolbox | ![]() ![]() |
Convert decimal value to binary vector
Syntax
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
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
.
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
bits
is greater than the minimum number of bits required to represent the decimal value, then the result is padded with zeros.
bits
is less than the minimum number of bits required to represent the decimal value, then the minimum number of required bits is used.
bits
is not specified, then the minimum number of bits required to represent the number is used.
Example
To convert the decimal value 23 to a binvec value:
To convert the decimal value 23 to a binvec value using six bits:
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.
Functions
![]() | daqschool | delete | ![]() |