File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

complement

 
Angela lewis
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why does it give -5 as the output?
 
Sanyev Babu
Ranch Hand
Posts: 132
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The binary of 4 "00000100"
If you do a complement if becomes "11111011" which is actually -5.
Just remember this when you do a complement on a positive number the resulting negative number will be one greater than the original positive number with a negative sign.

~4 = -(4+1)

When we are doing a complement we are actually doing a two's complement.
 
Corey McGlone
Ranch Hand
Posts: 3271
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic