• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one question

 
dpy learn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why 1111 1000 0000 0000 0000 0000 0000 0000=-134217728
 
Anatol Bollinger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked myself this question a couple of days ago. The method used is the two's complement: Wikipedia: Two's complement

Cheers, Anatol
 
dpy learn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh,i cannot see the Wikipedia: Two's complement
 
Rob Spoor
Sheriff
Pie
Posts: 20613
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An int is 32 bits. The first (left most) bit indicates the sign: 1 for negative, 0 for positive.
If the left most bit is 1, you can determine the number by changing each 1 to 0 and 0 to 1, then adding 1.

So:
1111 1000 0000 0000 0000 0000 0000 0000 = -134217728

Flip bits:
0000 0111 1111 1111 1111 1111 1111 1111 = 134217727

Add 1: 134217728.

And then add the - sign.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic