MATLAB Support Package for Velleman K8055/VM110 Experiment Board
22 Jul 2011
MATLAB library for communicating with a Velleman K8055/VM110 USB Experiment Interface Board
function result = int2binvec(A,length)
% int2binvec: Converts decimal integers to a 1xn binary vector.
% ans = int2binvec(A)
% Converts A to an 8-bit 1x8 binary vector. If A is larger than 8 bits
% (ie. A > 255), any higher-order bits will be truncated.
% ans = int2binvec(A,length)
% Converts A to a variable length binary vector, the size of which is
% defined by length. For example, if length = 20, it will create a 1x20
% Binary vectors are little endian, so each entry ans(i) corresponds to the
% 2^i-th place (ie. ans(1) is ones, ans(2) is twos, ans(3) is fours).
% Binary vectors longer or shorter than their decimal equivalents are
% truncated or padded with zeros as necessary.
% Copyright 2011 The MathWorks, Inc.
length = 8;
result = zeros(1,length);
for i = 1:length
result(i) = bitget(A,i);