function printbinary(n)
% PRINTBINARY - prints out binary representation of integer
%
% printbinary(n) prints out binary representation of integer n.
% Barnett 5/3/13

if n<0, error('n must not be negative'), end
if t==0, fprintf('0\n'); return, end    % handle n=0 correctly
t = 2^floor(log(n)/log(2));
while t>=1
  if n>=t, fprintf('1'), n = n-t;
  else, fprintf('0')
  end
  t = t/2;
end
fprintf('\n')    % terminate the string
