function ubvec = ui4_to_ubvec ( ui4, n )

%*****************************************************************************80
%
%% UI4_TO_UBVEC makes an unsigned binary vector from an unsigned integer.
%
%  Discussion:
%
%    A UBVEC is a vector of N binary digits.
%
%    A UBVEC can be interpreted as a binary representation of an
%    unsigned integer, with the first entry being the coefficient of
%    2^(N-1) and the last entry the coefficient of 1.
%
%    UBVEC   #
%    -----  --
%    00000   0
%    00001   1
%    00010   2
%    10000  16
%
%  Example:
%
%     I       BVEC         binary
%    --  ----------------  ------
%     1  0  0  0  0  0  1       1
%     2  0  0  0  0  1  0      10
%     3  0  0  0  0  1  1      11
%     4  0  0  0  1  0  0     100
%     9  0  0  1  0  0  1    1001
%    57  1  1  0  1  1  1  110111
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    19 November 2015
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer UI4, an integer to be represented.
%
%    Input, integer N, the dimension of the vector.
%
%    Output, integer UBVEC(N), the binary representation.
%
  if ( ui4 < 0 )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'UI4_TO_UBVEC - Fatal error!\n' );
    fprintf ( 1, '  Input integer is negative.\n' );
    error ( 'UI4_TO_UBVEC - Fatal error!' );
  end

  ui4_copy = ui4;
  ubvec = zeros ( n, 1 );

  for i = n : -1 : 1

    ubvec(i) = mod ( ui4_copy, 2 );

    ui4_copy = floor ( ui4_copy / 2 );

  end

  return
end
