1. How does 1 and-1 represent in memory?
2. How does one add a negative number to the memory?
3. Thinking Caused by an exercise.
First introduce a small tool to convert a char into a binary representation.
static void n2(unsigned char c) { int i; for (i = 0; i < 8; i++) { if (128 & c) putchar(‘1‘); else putchar(‘0‘); c <<= 1; } printf("\n");}
Usage:
n2(1);n2(-1);
Output:
1:00000001-1:11111111
Print several more numbers.
3:00000011-3:11111101 4:00000100-4:11111100
New discoveries:
The binary value of 1 is 00000001, And the inverse value is 11111110, and the value is 11111111, which is equal to-11111111.
The binary value of 3 is 00000011, And the inverse value is 11111100, and the value is 11111101, which is equal to-11111101.
The binary value of 4 is 00000100, And the inverse value is 11111011, and the value is, which is equal -.
The bold conclusion is that the negative sign is used for the binary bit of the memory.Returns the inverse value of 1..
Why are you thinking about this?
This is because of the problem of finding the minimum value of signed Char.
I am writing (char) (unsigned char )~ 0> 1) + 1)
The answer in the book is-(char) (unsigned char )~ 0> 1)
I can't figure out why I wrote the answer.The answer is wrong..
The title of this book is <C programming language (2nd) exercises>
What did the negative number do?