Data Acquisition Toolbox    
dec2binvec

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

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.

Remarks

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

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.

See Also

Functions

binvec2dec


  daqschool delete