MATLAB: Most efficient way to convert from binary to dec without bin2dec or bi2de

b2dbinary to decimalconversion

Is there a faster way to acomplish the following? The idea is to have an array of 5 bit inputs and convert each sequence of bits into a decimal.
p = [1 1 0 0 1; 1 0 0 0 1]
x = 2
[m n] = size(p);
y = zeros(m, 1);
for ii = 1:m
y(ii) = polyval(p(ii,:),x)
end
I want to be able to input 300,000 rows and 16 columns and eventually 32 or even 64 columns.

Best Answer

sum(p.*(2.^(size(p,2)-1:-1:0)),2)
Related Question