Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Got The Answer... no help needed

 
Manoj Paul
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider a machine that performs calculations 4 bits at a time. Eight-bit 2's complement numbers can be added by adding the four least significant bits, followed by the four most significant bits. The leftmost bit is used for the sign, as usual. With 8 bits for each number, add -4 and -6, using 4-bit binary 2's complement arithmetic. Did overflow occur?
Did carry occur? Verify your numeric result.




Ans:
Example:
Decimal: 20
Binary: 10100
Binary (8 bits): 0001 0100

Machine performance: 0001 and 0100 (i.e. 4 bits at a time)
Eight-bit 2�s complement numbers:
00010100
11101011 (1�s complement)
+1
---------------------------------------------
11011100 (2�s complement)
---------------------------------------------
Machine performance: 1100 and 1101 (4 bits each)

1100 (i)
1101 (ii)
---------------------------------------------
11001
00011001 (8 bits)
---------------------------------------------

For -4 = 1111 1100, (8 bits 2�s complement of 4) and
For -6 = 1111 1010 (8 bits 2�s complement of 6)


For (i)
0000 1100
Adding (-4)1111 1100
----------------------------
10000 1000
----------------------------

0000 1100
Adding (-6)1111 1010
----------------------------
10000 0110
----------------------------

For (ii)
0000 1101
Adding (-4)1111 1100
----------------------------
10000 1001
----------------------------

0000 1101
Adding (-6)1111 1010
----------------------------
10000 0111
----------------------------

So, from the above points (i) and (ii), we can find out that an overflow does occur and a carry does exist.


 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for you post.

This has nothing to do with JSP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic