aspose file tools
The moose likes Beginning Java and the fly likes Bit representation of negative numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Bit representation of negative numbers" Watch "Bit representation of negative numbers" New topic
Author

Bit representation of negative numbers

Gjorgi Var
Ranch Hand

Joined: Feb 24, 2004
Posts: 85
Bit representation of 32-bit integer 1 would be:
0000 0000 0000 0000 0000 0000 0000 0001
as it is positive number...
but -1 is represented as all 1's?
1111 1111 1111 1111 1111 1111 1111 1111

How come it's all 1's? Shouldn't 1 be just the first bit?
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

What do you think would happen if you added 1 to this number?


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
Negatives are two's complement.

http://en.wikipedia.org/wiki/Two's_complement
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Bit representation of negative numbers
 
Similar Threads
Question from Dan's Exam
operators
Shifting Rules?? (+/-SRS,+/-LS+/-URS)
left shift operation
Bitwise Inversion Operator