-1

I was wondering about this-

If A, B are 16-bit numbers and C is 8-bit, how many bits would I need to store the result ? 32 or 33 ?

And, what if C was a 16-bit number? What then ?

I would appreciate if I got answers with an explanation of the hows and whys.

Floose
  • 525
  • 2
  • 7
  • 15

1 Answers1

2

Why don't you just take the maximum value for each register, and check the result?

If all registers are unsigned:

0xFFFF * 0xFFFF + 0xFF = 0xFFFE0100 = // 32 bits are enough

0xFFFF * 0xFFFF + 0xFFFF = 0xFFFF0000 // 32 bits are enough

If all registers are signed, then 0xFFFF = -32767, but 0xFFFF * 0xFFFF would be the same as before (negative * negative = positive). Register C will make the result a little smaller than the previous result, but you would still require 32 bits in order to store it.

barak manos
  • 29,648
  • 10
  • 62
  • 114
  • How do i multiply FFFF and FFFF to get what you said ? When I do paper and pencil multiplication, at certain points I am getting 1+1+1+1 - what is the sum bit and carry bit here? – Floose Jan 14 '14 at 12:12
  • Ah yes, my other question was what would happen if this were signed representation ? what would be the max number i can store then – Floose Jan 14 '14 at 12:14