| Arithmetic: overflow | ||||||||||||||
| So far, we have always assumed that we have enough bits to represent a value. | ||||||||||||||
| However, a computer must work with a finite number of bits. | ||||||||||||||
| What happens if the result doesn't fit in the available bits? | ||||||||||||||
| This is called overflow. | ||||||||||||||
| Overflow occurs when the result of an operation is greater than the max possible value | ||||||||||||||
| or less than the min value. | ||||||||||||||
| In UB: | ||||||||||||||
| carry | 1 | 1 | 1 | 1 | ||||||||||
| 1 | 0 | 1 | 1 | 11 | ||||||||||
| 0 | 1 | 1 | 1 | 7 | ||||||||||
| result | 0 | 0 | 1 | 0 | 2 | |||||||||
| What should the result be? | ||||||||||||||