wood burning stoves 2.0*
The moose likes JSP and the fly likes Got The Answer... no help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Got The Answer... no help needed" Watch "Got The Answer... no help needed" New topic
Author

Got The Answer... no help needed

Manoj Paul
Ranch Hand

Joined: Jan 18, 2007
Posts: 112
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

Joined: Dec 11, 2004
Posts: 13410

Please take the time to choose the correct forum for you post.

This has nothing to do with JSP.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Got The Answer... no help needed
 
Similar Threads
Shift operators!
Operators
octal/hex/binary/unicode ?
Can anyone help me regarding
operators