python - Why Wouldnt This Binary Division Program Display the Correct Quotient? -


import comparator, bitwise_operator  def divide(dividend, divisor, quotient_remainder):     operand = []     divisor_length = len(divisor)     try:         value in range(divisor_length):             operand.append(dividend.pop(0))             divisor_length -= 1     except indexerror:         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])) 

the module "bitwise operator" bitwise in operations, in case, subtraction.

the module "comparator" returns 01, 10 or 11 if less than, more or equal b.

ive been trying make binary division program ages, trying same approach every time. 1 has been successful, displays correct modulo, quotient off. far know, correctly follows binary long division method.

does know why doesn't work??? it's frustrating. ive looked throug , fixed mistakes, how right should working.

unfortunately, cannot give imported modules. analyse code , see did wrong, i.e. incorrect binary division method? i'll highly appreciate :d


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -