title: Why Wouldn't this Binary Division Program Display the Correct Quotient?
body: <pre><code>import comparator, bitwise_operator
  
  def divide(dividend, divisor, quotient_remainder):
      operand = []
      divisor_length = len(divisor)
      try:
          for value in range(divisor_length):
              operand.append(dividend.pop(0))
              divisor_length -= 1
      except IndexError:
          for value in range(divisor_length):
              operand.insert(0, 0)
      quotient = []
      remainder = []
      while len(dividend) != 0:
          if comparator.compare(list(operand),
                                list(divisor)) in [[1, 1], [1, 0]]:
              quotient.append(1)
              operand = bitwise_operator.operate(
                  list(operand),
                  list(divisor),
                  [0, 1, 1, 0, 1, 0, 0, 1],
                  [0, 1, 1, 1, 0, 0, 0, 1],
                  [0, 0])
              operand.append(dividend.pop(0))
          elif comparator.compare(list(operand), list(divisor)) == [0, 1]:
              quotient.append(0)
              operand.append(dividend.pop(0))
      remainder = operand
      while comparator.compare(list(remainder),
                               list(divisor)) in [[1, 1], [1, 0]]:
          remainder = bitwise_operator.operate(list(remainder),
                                               list(divisor),
                                               [0, 1, 1, 0, 1, 0, 0, 1],
                                               [0, 1, 1, 1, 0, 0, 0, 1],
                                               [0, 0])
          quotient = bitwise_operator.operate(list(quotient),
                                              [1],
                                              [0, 1, 1, 0, 1, 0, 0, 1],
                                              [0, 0, 0, 1, 0, 1, 1, 1],
                                              [0, 0])
      if quotient == []:
          quotient = [0]
      if quotient_remainder == [1, 0]:
          return(quotient)
      elif quotient_remainder == [0, 1]:
          return(remainder)
  
  def quotient(dividend, divisor):
      return(divide(dividend, divisor, [1, 0]))
  
  def modulo(dividend, divisor):
      return(divide(dividend, divisor, [0, 1]))
  </code></pre>
  
  <p>The module "bitwise operator" does bitwise in operations, in this case, it does subtraction.</p>
  
  <p>The module "comparator" returns 01, 10 or 11 for if A is less than, more than or equal to B.</p>
  
  <p>Ive been trying to make a binary division program for ages, trying the same approach every time. This one has been my most successful, as it displays the correct modulo, but the quotient is off. As far as I know, it correctly follows the binary long division method.</p>
  
  <p>Does anybody know why it doesn't work??? It's really frustrating. Ive looked throug it and fixed mistakes, but how it is right now should be working.</p>
  
  <p>Unfortunately, I cannot give you the imported modules. But could anybody analyse my code and see what I did wrong, i.e. Incorrect binary division method?</p>