| Data Acquisition Toolbox™ | ![]() |
out = dec2binvec(dec) out = dec2binvec(dec,bits)
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. |
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.
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.
To convert the decimal value 23 to a binvec value:
dec2binvec(23)
ans =
1 1 1 0 1To convert the decimal value 23 to a binvec value using six bits:
dec2binvec(23,6)
ans =
1 1 1 0 1 0To 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![]() | daqreset | delete | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |