Why 2147483648
In fact, it has been the state of fish hunting recently, and programming is also very rare. In fact, I really want to think about it for a while. All I have to worry about is just time to think about code. It seems that I am idle, but now I feel useless in everything.
This problem is due to the experiment in our C language class.
#include <stdio.h>int main(){ int max(int x,int y); int a,b,c; while (1){ printf("input a&b: "); scanf ("%d,%d",&a,&b); c=max(a,b); printf("max=%d\n",c);} return 0;}int max(int x,int y){ int z; if (x>y) z=x; else z=y; return z;}
There was nothing, but suddenly an old brother seemed to have discovered the new world.
"Oh sorry, it broke out." = ", the input is too large to output a negative number that is not between the two.
Immediately lost the boring experiment content and began to study the nature of the problem. ActuallyData OverflowRight.
Lab content
As a matter of fact, I have learned that the int range is-231 ~ in vc6 ~ 231-1, that is,-2147483648 ~ 2147483647. So I started to test it out.
It is indeed the power of 2147483647.
But now there is a new question: where did-1141710350 come from?
Monitoring variable
I used to program to view the content in a variable without stopping using print and MessageBox ..
Know that you can use monitoring now
It can be found that the value of 123412341234 is immediately changed to-1141710350.
In this case, please go out to the programmer calculator ..
From the test above, we can see that this number is related to 123412341234.
And its binary code is?0001 1100 1011 1011 1111 0010 1110 0001 1111 0010?
If only 32 bits are retained1011 1011 1111 0010 1110 0001 1111 0010
Here is exactly the binary code of-1141710350.
PS: The bit keyboard is really fun =
Go crazy on the edge of 2147483647