*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes complement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "complement" Watch "complement" New topic
Author

complement

Angela lewis
Ranch Hand

Joined: Mar 01, 2004
Posts: 100


why does it give -5 as the output?
Sanyev Babu
Ranch Hand

Joined: Dec 18, 2003
Posts: 132
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

Joined: Dec 20, 2001
Posts: 3271
Negative Numbers in Java - Two's Complement


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: complement
 
Similar Threads
for loop question
assignments and + operator
lockCookie
Access a variable
JSP called from filter not finding JavaScript file