function k = i4_and ( i, j )

%*****************************************************************************80
%
%% i4_and() calculates the AND of two integers.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 January 2016
%
%  Author:
%
%   John Burkardt
%
%  Input:
%
%    integer I, J, two values whose exclusive OR is needed.
%
%  Output:
%
%    integer K, the AND of I and J.
%
  k = 0;
  l = 1;

  i = floor ( i );
  j = floor ( j );

  while ( i ~= 0 || j ~= 0 )
%
%  Check the current right-hand bits of I and J.
%
    i2 = floor ( i / 2 );
    j2 = floor ( j / 2 );

    if ( ( i ~= 2 * i2 ) && ( j ~= 2 * j2 ) )
      k = k + l;
    end

    i = i2;
    j = j2;
    l = 2 * l;

  end

  return
end
