Integer overflow occurs in computers, when the number which is stored becomes larger than the capacity of the memory it is stored in.
The most likely result is that the number will reset to 0 and start over.
For example, start with the number 14, using 4-bits integers. Add 1 a few times, this will result in an overflow, which causes it to reset the number to 0.
Binary number | Decimal number |
---|---|
1110 | 14 |
1111 | 15 |
0000 | 0 |
0001 | 1 |
Another result is the number will reset to the most negative number, if the number has a sign. This is because negative numbers are represented by values after the maximum positive value.
For example, with signed 4-bit integers. Adding 1 will cause this type of overflow:
Binary number | Decimal number |
---|---|
0110 | 6 |
0111 | 7 |
1000 | -8 |
1001 | -7 |
This article uses material from the Wikipedia Simple English article Integer overflow, which is released under the Creative Commons Attribution-ShareAlike 3.0 license ("CC BY-SA 3.0"); additional terms may apply (view authors). Content is available under CC BY-SA 4.0 unless otherwise noted. Images, videos and audio are available under their respective licenses.
®Wikipedia is a registered trademark of the Wiki Foundation, Inc. Wiki Simple English (DUHOCTRUNGQUOC.VN) is an independent company and has no affiliation with Wiki Foundation.