136

‎3,000,000,000 == -1,294,967,296

Comments
  • 35
    Yay for integer overflow
  • 5
    @VirtualProtect 2^32 = 4294967296 and since int is signed it is from -2147483648 to 2147483648 (something like that, maybe +- 1 on one of the too). But where do they get the -1294967296 from 🤔 or did I miss a lesson in it?
  • 17
    Yup you're right! So since 3 billion (3,000,000,000) is greater than 2,147,483,648, it overflows into the negatives. 3 billion in hex is 0xB2D05E00. If you convert hex to signed int, you get -1294967296
  • 1
    @VirtualProtect I'll need to ask my teacher about signed numbers and how they are presented in binary one more time... I didn't understand how the 32 bit become split up into positive/negative halves :/ or I'll just ask google. Probably its different from system to system idk
  • 7
    @b3b3 signed / unsigned int are simply just interpretations of memory. In memory, 0xB2D05E00 is what's stored. It's up to your program to interpret this information. If your program expects an unsigned (32 bit) integer, the value is 3,000,000,000. If it expects a signed int it will be -1294967296. This is dependant on how many bits a system uses to represent an int.
  • 3
    @b3b3 Search for two's complement
  • 2
    "yes"
    😆😂😂😂
  • 0
    Thing is, if you ask it to "pick", it works just fine. If you ask it to guess, it gets confused. 😶
Add Comment