This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 11858


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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: 2's compliment
It's not a secret anymore!