This week's book giveaway is in the Other Languages forum.We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# one question

dpy learn
Greenhorn
Posts: 4
why 1111 1000 0000 0000 0000 0000 0000 0000=-134217728

Anatol Bollinger
Greenhorn
Posts: 11
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
oh,i cannot see the Wikipedia: Two's complement

Rob Spoor
Sheriff
Posts: 20669
65
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