Go crazy on the edge of 2147483647

Source: Internet
Author: User
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 0010Here is exactly the binary code of-1141710350.


PS: The bit keyboard is really fun =

Go crazy on the edge of 2147483647

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.