function powers3 ( m, n )

%% POWERS3 represents integers by a vector of M binary digits.

  p = zeros ( m, 1 );
  p(1) = 1;
%
%  Do this N+1 times.
%
  for i = 0 : n
%
%  Print current value.
%  Insert comma.
%  Could we omit leading zeros also?
%
    fprintf ( 1, '  %2d  ', i );
    for j = m : -1 : 1
      fprintf ( 1, '%d', p(j) );
      if ( mod ( j, 3 ) == 1 && 1 < j )
        fprintf ( ',' );
      end
    end
    fprintf ( 1, '\n' );
%
%  Get next power of 2 by doubling every digit.
%
    p = 2 * p;
%
%  Actually, if p(m) is 10 or more, we have overflowed.
%  We should generate an error and stop.
%
    if ( 10 <= p(m) )
      error ( 'Overflow in POWERS3!' )
    end
%
%  If any digit is 10 or greater, we need to "carry" the 1.
%
    while ( any ( 10 <= p ) )
      k = find ( 10 <= p );
      p(k)   = p(k) - 10;
      p(k+1) = p(k+1) + 1;
    end 

  end

  return
end
