% addone.m % "adds one" to the current vector % % inv = input vector function r = addone (inv) r = inv; foo = size(r); n = foo(2); % this is the "width" of the input vector c = 0; % this is to check if there's a problem. 0 means there is position = 1; while position <= n if r(position) == 0 r = flipbit(r,position); position = n+1; % so that the while loop ends c = 1; elseif r(position) == 1 r = flipbit(r,position); position = position+1; end end