Integer overflow

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.

A mechanical form of integer overflow. All digits are set to the maximum 9, and adding 1 causes it to reset to 0.

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 numberDecimal number
111014
111115
00000
00011

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:[1]

Binary number Decimal number
0110 6
01117
1000-8
1001-7

References


This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.