Possible Duplicate:
Converting binary to decimal without using loop
I’m looking for the simplest and fastest solution. I tried documentation but could find anything.
I have an array of bits like [0, 1, 1, 1] and I want to convert it to simple int number 7. I get this array with bitget(x, 1:3), where x is an integer.
@Edwin’s answer uses binvec2dec which is part of the Data Acquisition Toolbox. This toobox is an additional toolbox (developed by Mathworks) but not part of the base MATLAB package.
Here is a solution that does not depend on this toolbox.
Use num2str to convert the binary array to a string
str=num2str(bin_vec);
use bin2dec to get decimal value
dec_num=bin2dec(str);