0
\$\begingroup\$

I saw somewhere that if we have A (dividend) which is 2n-bits and B (divisor) which is n-bit, we can store the quotient in n-bits with a specific condition: the (n-1)th bit of the divisor has to be 1.

If this condition is met, we can always store the quotient and remainder in n-bits. But I can't understand it.

Let's say we take n as 4, A as 11111111 and B as 1000. The quotient will then be 11111, which is 5 bits.

So did the person in the video explain it wrong or am I misunderstanding it?

\$\endgroup\$
2
  • \$\begingroup\$ Without any reference, it is hard to tell what has presented "somewhere". While unlikely, it may have been mantissas with "hidden"/omitted MSB. \$\endgroup\$ Commented Feb 25, 2024 at 23:04
  • \$\begingroup\$ Are the numbers unsigned, twos complement signed, or using a sign bit? The format probably matters here. \$\endgroup\$ Commented Feb 29, 2024 at 14:13

2 Answers 2

2
\$\begingroup\$

If you have any value and divide it by 1, you need exact same amount of bits for the quotient and there is no remainder.

Divide it by 2, which uses one more bit, means you can use one less bit for the result, and you need to use one bit for the remainder, so same amount of bits for the result.

Divide the original number by 4, and result uses two bits less, but you need 2 bits for remainder, again same amount in total.

With these examples, it's clear that every time you add one more divisor bit you will split the result between quotient and remainder and they sum up at most equal amount of bits than the original value you are dividing.

This also is not specific to binary numbers but numbers in all places. Let's compare with decimal numbers. If you have any length decimal number, and divide it by 10 or 1 or 100, you have same amount of decimal digits but the decimal point moved by one digit.

\$\endgroup\$
1
  • \$\begingroup\$ Where I have an m places number and divide it by a d place divisor not a power of the base, I get an m + 1 - d place quotient and a d place remainder. \$\endgroup\$ Commented Feb 29, 2024 at 9:53
0
\$\begingroup\$

I'll talk about how to get maximum precision out of the operation, below.

Let's first set up what integer division is, though. Here, \$\frac{\mathcal N}{\mathcal D}=\mathcal Q\:\: r\:\: \mathcal R\$ where \$\mathcal N=\mathcal Q\cdot \mathcal D+\mathcal R\$ is exact.

It's not uncommon in hardware division, where the word-size is \$n\$ bits, that \$\mathcal N\$ is \$2n\$ bits wide, \$\mathcal D\$ is \$n\$ bits wide, \$\mathcal Q\$ is \$n\$ bits wide, and \$\mathcal R\$ is \$n\$ bits wide. So I think your situation is standard fare and I agree with your problem setup, which means I can proceed with the idea that I understand your question well enough.

\$\mathcal N\$ is two words in size. Let's say that the upper word is called \$\mathcal N_1\$ and the lower word is called \$\mathcal N_0\$. Before starting the division operation, it is your responsibility to ensure that \$\mathcal D\$ has been normalized such that its upper bit is always a '1', that \$\mathcal N\$ has also been normalized such that its upper bit is always a '1' but then subject also to the requirement that \$\mathcal N_1\lt\mathcal D\$. The reason for that is that \$\mathcal R\lt \mathcal D\$ (the remainder must be less than the divisor.) So if this requirement isn't met after normalization, then an additional step requires that \$\mathcal N\$ must now be downshifted one bit.

During this normalization process, you must also keep track of the exponent (the difference between number of shifts used for \$\mathcal N\$ and for \$\mathcal D\$.)

You are violating the above in your case.

\$\mathcal D=1000\$ is normalized already. So you don't need to do anything with it. And \$\mathcal N=1111:1111\$ is also normalized. But then this fails the test that \$\mathcal N_1\lt \mathcal D\$ so you must perform a down-shift so that \$\mathcal N=0111:1111\$. That way \$\mathcal N_1\lt\mathcal D\$.

However, in doing so you also have to note (somewhere) that the exponent is 1 and that you shifted off a '1' bit when appropriately adjusting \$\mathcal N\$ before division.

If you follow the above, then it will always be the case that \$\mathcal Q\$ is \$n\$ bits wide and that \$\mathcal R\$ is also \$n\$ bits wide, but consistent also that \$\mathcal R\lt \mathcal D\$. (Note that in your case where \$\mathcal D=1000\$ (the smallest normalized value possible) that \$\mathcal R\le 0111\$ (so in this case the uppermost bit of \$\mathcal R\$ must be always '0' when in the unique situation where \$\mathcal D=1000\$.)

Now, for your case properly handled you will get \$\mathcal Q=1111\$ (which is 4 bits) and \$\mathcal R=0111\$. So the final result is \$\left(1111\cdot 1000+0111\right)\cdot 2^1+1=1111:1111\$. Or put another way, \$\left(1111+\frac{0111}{1000}\right)\cdot 2^1+\frac1{1000}\$.

In decimal, \$\left(15+\frac78\right)\cdot 2+\frac18=31.875\$. This is the same as \$\frac{255}8=31.875\$, which was your original setup.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.