wood burning stoves
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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 ......is it the same way
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11882


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: http://aspose.com/file-tools
subject: 2's compliment
It's not a secret anymore!