function [x] = dec2bv(a,p)
% Computes the binary equivalent of the decimal number a; returns the
% value as a 1-by-p array of ones and zeros.
%
% Copyright (c) 2008 Karl J A Petre and Xavier J Ortiz.
% This file was last updated 7 December 2008.
%
% This code is included with the Matlab Whirlpool package.
%
% The Whirlpool algorithm was developed by:
% Paulo S. L. M. Barreto (pbarreto@scopus.com.br)
% Vincent Rijmen (vincent.rijmen@cryptomathic.com)
%
% This software is provided by the author as is and any express
% or implied warranties, including, but not limited to, the implied
% warranties of merchantability and fitness for a particular purpose
% are disclaimed. In no event shall the author or contributors be
% liable for any direct, indirect, incidental, special, exemplary, or
% consequential damages (including, but not limited to, procurement of
% substitute goods or services; loss of use, data, or profits; or
% business interruption) however caused and on any theory of liability,
% whether in contract, strict liability, or tort (including negligence
% or otherwise) arising in any way out of the use of this software,
% even if advised on the possibility of such damage.
if nargin < 2; p = 64; end % Assume long precision.
e = 0;
while 2^e < a
e = e+1;
end
x = zeros(1,e);
for i = e:-1:0
if a >= 2^i
x(i+1) = 1;
a = a-2^i;
end
end
x = [zeros(1,p-length(x)) fliplr(x)];