function [x] = bv2hex(a)
% Computes the hexadecimal equivalent of the binary number a, which is
% expressed in a 1-by-length(a) 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.
x = [];
m = length(a);
a = fliplr(a);
j = 1;
while j < m
y = 0;
b = fliplr(a(j:j+3));
for i = 1:4
if b(i)
y = y+2^(4-i);
end
end
x = [x dec2hex(y)];
j = j+4;
end
if length(a(j:end)) > 0
y = 0;
b = fliplr(a(j:end));
for i = 1:m-j+1
if b(i)
y = y+2^(length(a(j:end))-i);
end
end
x = fliplr([x dec2hex(y)]);
else
x = fliplr(x);
end