*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "2 Watch "2 New topic
Author

2's compliment

cybel sheriden
Ranch Hand

Joined: Jan 18, 2005
Posts: 50
hi

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
Bartender

Joined: Oct 02, 2003
Posts: 11168
    
  16

Cybel,

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
 
 
subject: 2's compliment
 
Similar Threads
Using ~ (Unary bitwise complement) for Zero
what will be the sign!!
~ operator !
The sign of zero
Y 2's compliment notion used to store the value of a variable?