• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bit representation of negative numbers  RSS feed

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think would happen if you added 1 to this number?
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Negatives are two's complement.

http://en.wikipedia.org/wiki/Two's_complement
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!