8
$\begingroup$

I am stumped on a simple problem. Let's say I have two 4 bit numbers in Q0.3 format. One sign bit and three fractional bits. So I can represent $-1$ through to $0.875$.

Let's now say I wish to do this calculation: $-0.25 \times 0.875$. Which is:

$$ \frac{-2}{2^3} \times \frac{7}{2^3} $$

Which means I am multiplying $1110$ ($-2$) by $0111$ ($7$). Of course the answer is $-0.21875$ or $-0.25$ using the closest Q0.3 number.

Let's do the working.

$$ 1110 \times 0111 = 01100010 $$

which when viewed as a Q0.6 number is $1.100010$, which is $-0.46875$ by my books. Why is this incorrect? I expect an answer of $1.110010$ ($-0.21875$).

What have I done wrong?

$\endgroup$
10
$\begingroup$

When multiplying two's complement numbers, you have to perform sign extensions to the operands to meet the number of digits your multiplication will yield, i.e., in your case $4 + 4 = 8$ digits.

$$ 11111110_2 \times 00000111_2 = 11110010_2 $$

As there are $2 * 3$ fractional bits, the result is $1.110010_2 = \frac{-14}{2^6} = -0.21875$. Normalizing this number to $3$ fractional bits in Q0.3 format yields $1.110_2 = -0.25$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.