function c = i4_to_digits_binary ( i, n ) %*****************************************************************************80 % %% I4_TO_DIGITS_BINARY produces the binary digits of an I4. % % Discussion: % % An I4 is an integer. % % Example: % % I N C Binary % -- --- --- ------------ % 0 1 0 0 % 0 2 0, 0 00 % 1 3 1, 0, 0 100 % 2 3 0, 1, 0 010 % 3 3 1, 1, 0 011 % 4 3 0, 0, 1 100 % 8 3 0, 0, 0 (1)000 % 8 5 0, 0, 0, 1, 0 01000 % -8 5 0, 0, 0, 1, 0 (-) 01000 % % 0 3 0, 0, 0 % 1 3 1, 0, 0 % 2 3 0, 1, 0 % 3 3 1, 1, 0 % 4 3 0, 0, 1 % 5 3 1, 0, 1 % 6 3 0, 1, 1 % 7 3 1, 1, 1 % % Licensing: % % This code is distributed under the GNU LGPL license. % % Modified: % % 19 December 2011 % % Author: % % John Burkardt % % Parameters: % % Input, integer I, an integer to be represented. % % Input, integer N, the number of binary digits to produce. % % Output, integer C(N), the first N binary digits of I, % with C(1) being the units digit. % i_copy = floor ( abs ( i ) ); c = zeros ( n, 1 ); for j = 1 : n c(j) = mod ( i_copy, 2 ); i_copy = floor ( i_copy / 2 ); end return end