%Let x be a bitstring and suppose x is the i-th string in %the list of all bitstrings 0, 1, 00, 01, 10, 11, 000, ... % Then, bitstring_to_index(x) = i. The integer i shall be %called the index of x. % % Usage: % i = bitstring_to_index( [ 0 0 ] ) % returns i = 3. % t = concat( i )' % recovers the original bits [ 0 0 ]. % (Perhaps concat() should be renamed index_to_bitstring). % % WARNING: because we are using IEEE754 doubles, % we only have 53 bits (of mantissa), % the integer 2^53+1 % is the smallest positive integer that % cannot be exactly represented: % (2^53+1)-(2^53) % is rounded off to zero. % This means that a "index" % can represent bitstrings of up to 52 bits. % (53 bit bitstrings will always round the last % bit off to zero). % % See also CONCAT, PRINT_BITSTRINGS, BINARY_TO_INDEX, BITMAX. % by John C. Kieffer % http://www.ee.umn.edu/users/kieffer/programs.html % documented in % ftp://oz.ee.umn.edu/users/kieffer/seminar/notes1.ps % more documentation by David Cary 1999-05-06 function y=bitstring_to_index(x) N=length(x); if(53 <= N ) error('Sorry, this is too big for me to handle.') end; S=1; for i=1:N; S=2*S+x(i); end y=S-1;