---
# System prepended metadata

title: CAOS Exercise Session Lecture 2

---

# CAOS Exercise Session Lecture 2

### 2.17 p. 101

0x1 : 0001 : $2^0$
0xB : 1011 : $2^3 + 2^1 + 2^0$

### 2.21 p 112

$-2147483647-1 == 2147483648U$
Type: unsigned
Evaluation: It be true
Almost TMIN: 10000000000000000000000000000001

Almost TMIN-1: 10000000000000000000000000000000
UDetdertal
10000000000000000000000000000000

$-2147483647-1 < 2147483647$
Type: Signed
Evaluation: True

$-2147483647-1U < 2147483647$
Type: Unsigned
Evaluation: False get fucked
10000000000000000000000000000001
00000000000000000000000000000001

10000000000000000000000000000000

$-2147483647-1 < -2147483647$
Type: Unsigned
Evaluation: True

$-2147483647-1U < -2147483647$
Type: Unsigned
Evaluation: True

$10000000000000000000000000000001 - 00000000000000000000000000000001 =
10000000000000000000000000000000$

10000000000000000000000000000001

### 2.29 p. 129

$x = 10100, y = 10001$
$x + y = 100101$
$x +^t_5 y = 00101$
Case: 1, fordi negativ overflow

$x = 01100, y = 00100$
$x + y = 10000$
$x +^t_5 y = 10000$
Case: 4

### 2.30 p. 130
``` c
int tadd_ok(int x, int y) {
    // Case 4: Positive overflow
    if(x > 0 && y > 0 && x + y < 0) {
        return 0;
    } 
    // Case 1: Negiative overflow
    else if(x < 0 && y < 0 && x + y > 0) {
        return 0;
    }
    return 1;
}
```

### Challenge 0
