0
Hi, I’m writing algorithms for large numbers. I implemented the operations of sum, division and subtraction but for divide I have no idea just an algorithm to use with binary base. It is not an option to turn the number to binary, I want to use base 10.
The numbers I want to divide are represented as follows:
2346
|2|->|3|->|4|->|6|
It’s a circular list.
How can I do?
I’ll leave the recursive binary algorithm to the division:
funcao divide(x,y)
entrada: dois numeros inteiros de n bits x e y, onde y >= 1
saida: o quociente e o resto de x dividido por y
se x = 0 : retorn (q,r) = (0,0)
(q,r) = divide(floor(x/2),y)
q = 2*q, r = 2*r
se x é impar: r = r + 1
se r>=y: r = r - y, q = q + 1
retorna (q,r)