32,767
look closer :) 32768 (because zero... it took one of the bit positions to represent zero, so this is how many "values" it can hold, 0-32767 is 32768 possible values).
anyway 32768 is... 2 to the 15th power. if you had used an unsigned int, it would have been 2 to the 16th power -1, 65535. Try it again with unsigned and put that value in it :)
you can find out how big the number can be by 2 to the number of bits, then, or find out what a number needs to be stores with lg (that's log base 2 symbol) of the number: lg 65536 is 16 …
does that help?
one more thing: what is the ascii lookup value of ~?
why, it appears to be... 126! you are printing a character, and that char happens to be 126, that is where the ~ came from and why it printed "nothing" in your mind when you expected a value. do this
char x = '~';
cout << (int)x << endl;
the most significant bit of a signed value is sometimes called the sign bit, but negative numbers are a little more complex than that. they use a neat property of binary --- flip the bits and add 1, and that is the negative value.
for example, for a byte, 00001111 is 15. minus 15, then is 11110001, try it in windows calc in programmer mode in binary. now add them together...
1 2 3 4 5
|
00001111
11110001
100000000 //but the 1 on the far end is discarded and its zero.
|