0
$\begingroup$

Which of the following hexadecimal numbers, representing signed 16-bit binary numbers, results in overflow when multiplied by 4? Here, a negative number is represented in 2's complement.

a. 1FFF    b. DFFF,    c.E000, d.FFFF

Does this mean that I have to convert all the values from a to d to binary, then represent them in 2's complement, then multiply them by 4? For example :

1FFF = 0001 1111 1111 1111 (binary) 
= 1110 0000 0000 0001 (2's complement)  
2's complement * 4 = 11 1000 0000 0000 0100 

But I think I misunderstood the question, because the results after multiplying by 4 for all values exceed 16-bit binary, mean they all get over flow after the multiplication

Please clarify if there is any blunders I'm having. Thanks!

$\endgroup$
1
$\begingroup$

You are expected to take those numbers to be already in 2's complement notation. $1FFF$ is the same in binary and 2's complement, because it is positive. If the MSB is set in 2's complement, the number is negative, otherwise it is positive. The point is that one neat thing about 2's complement is you don't worry about the sign, you just multiply. So $1FFF \cdot 0004=7FFC$, which doesn't overflow. The hard part is when multiplying by a negative will overflow.

$\endgroup$
  • $\begingroup$ Thanks. But I still don't get the part when 1FFFF * 0004 = 4FFC? My calculation is 7FFC. Please show me how did you multiply it! $\endgroup$ – f855a864 Oct 18 '14 at 5:11
  • 1
    $\begingroup$ You’re correct that $0x1FFF\times 4=0x7FFC$. (This still doesn’t overflow, since the most significant bit has not changed.) $\endgroup$ – Steve Kass Oct 18 '14 at 5:22
  • $\begingroup$ @SteveKass how about DFFF and E000, I multiply them by 4 and the results are all 18-bits, which exceeds the 16 bit range? $\endgroup$ – f855a864 Oct 18 '14 at 5:27
  • $\begingroup$ Basically the lower $15$ bits are data. If multiplying takes any data even into the top bit, you have an overflow $\endgroup$ – Ross Millikan Oct 18 '14 at 13:46
  • $\begingroup$ Ross: All 16 bits are data. For two 16-bit two’s complement signed integers, the right 16 bits of the product is wrong if either a) there’s a carry past the 16th bit, or b) the most significant bit (it’s 1 for negative numbers and negative numbers only) shows a wrong +/- sign for the answer. [Math note: two’s complement arithmetic is arithmetic modulo 2^15, with answers interpreted as between -2^15 and 2^15-1] f855a864: Neither of the negative numbers DFFF or E000 can be multiplied by 4 without a wrong 16-bit answer. (My earlier "most significant bit has not changed" was not a general answer.) $\endgroup$ – Steve Kass Oct 18 '14 at 14:44

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.