function y = decimalToBinary(x, varargin)
      switch nargin
            case 1
                  if log2(x) < 1
                        len = 1;
                  else
                        len = floor(log2(x)) + 1;
                  end
                  y = zeros(1, len);
                  tmp = len - 1 : -1 : 0;
                  divisor = 2 .^ tmp;
                  for i = 1 : 1 : length(divisor)
                        if x / divisor(i) >= 1
                              x = x - divisor(i);
                              y(i) = 1;
                        end
                  end
            case 2
                  len = varargin{1};
                  if len < log2(x)
                        len = floor(log2(x)) + 1;
                        warning(['Binary length = ' num2str(len)])
                  end
                  y = zeros(1, len);
                  tmp = len - 1 : -1 : 0;
                  divisor = 2 .^ tmp;
                  for i = 1 : 1 : length(divisor)
                        if x / divisor(i) >= 1
                              x = x - divisor(i);
                              y(i) = 1;
                        end
                  end
            otherwise
                  error('Wrong input.');
      end
end