Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How do I make a divider?

A topic by MyNameIsToday created Mar 03, 2024 Views: 748 Replies: 7
Viewing posts 1 to 4

I have addition subtraction, and multiplication. I now want division, so does anybody know how to make a 4 or 8 bit divider, or have a save file with one for me to look at, and/or use.

(+1)

So,  I'll do  my best to explain what (hypothetically) might work...

If you divide  for example 8 ÷ 4. Division is basically subtracting (from the dividend) until the number is less then the second number (divisor). So what you could do is have a circuit that loops through itself until a condition is met, then ending the loop and outputting a result. Here's a step-by-step guide to how it (could) work:

Input A = 8 and Input B = 4

So take 4 (B) from 8 (A) and then add one to C (now 1), so A is now 4 and B is still 4.

Then if A (now 4) is less then B (4) we would stop. But A (4) is not less then B (4), SO! We can do another subtraction so A is now 0 and B is 4, and we add one to C (now 2).

So A (8) ÷ B (4) = C (2), and we would output C (2).

So we could input our two numbers (A & B) and loop through a Subtraction Circuit, checking each time if A is less then B, and if so we stop the loop, and output or C (answer). Now this would take a lot of work, but seems possible.

But if you wanna do something easier (but bulkier) you could chain-together a bunch of subtractions (adding 1 to a counter every circuit), and check each time if it is less then, and if so stopping the chain and outputting a result.

I hope all of this makes sense. And if it does, hope it helps.

Thank you, hopefully I can make something out of it, and hopefully it helps others looking on how to make a divider too! :) I also already have a comparator to detect if a number is greater, less than, or equal to the other, so that will help with this.

(1 edit)

Nice! I hope that was able to help. I would definitely like to hear if you made any progress, and if my idea actually worked.

Deleted 263 days ago

It worked! It isn't completely automatic, but it works with most numbers I tested!

👍

I know I'm late but, you can very easily do division in O(1) using long division, here's an implementation for 8 bits:

I have found that this works but has some glitches. I also like to turn the down signal into the off signal so I can or it easier. thats what the TFORMs are for