# Written Assignment 1

### Question 1

For adding two signed integers of the same bit width, describe the cases where overflow can occur, and how it can be detected.

If the two signs are different, there is no overflow. If the two signs are the same, there might be an overflow. In this case, the overflow can be detected by adding the two signed integers together and look at the sign of the added result. If the sign matches with the sign of original inputs (recall that we are on the case of two signs are the same), then there is no overflow. If the sign does not match with the sign of the original input, then there is an overflow.

### Question 2

Explain why or why not the associative and commutative properties for integers hold. Are there any edge cases?

Associative and commutative properties hold for 2s-complement and unsigned integers because they obey the property of modular arithmetics. For addition and multiplication, 2s-complement and unsigned integers strictly follow the rules of modular arithmetics because there is no rounding take place which ensures associative and commutative properties hold as they hold with modular arithmetics. Of course, division and subtraction are neither associative nor commutative as expected.

Table of Content