File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes 2's compliment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2 Watch "2 New topic

2's compliment

cybel sheriden
Ranch Hand

Joined: Jan 18, 2005
Posts: 50

2's comliment of negative value is .....flip all bits and add 1.
2's compliment of positive value it the same way
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11957


the process of 2's complement really doesn't know anything about positive or negative. it just means "flip the bits and add 1".

How those bits are interpreted are up to you (and the computer). If you're really asking "how do i find the bit pattern of a negative integer", or "what integer is represented by such-and-such a bit pattern" that's a little different.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: 2's compliment
It's not a secret anymore!