CSAPP 第二章 课程作业

2.58

typedef unsigned char *byte_pointer;

int is_little_endian(int x = 1)
{
    byte_pointer y = (byte_pointer)&x;
    return !!y[0];
}```
## 2.62
```cpp
int int_shifts_are_arithmetic()
{
    int x = -1;
    int y = (x << 1) >> 1;
    return x == y;
}

2.74

int tsub_ok(int x, int y)
{
    if(y == -y && y != 0)
        return x > 0;
    y = -y;
    int sum = x + y;
    bool pos_over = x >= 0 && y >= 0 && sum < 0;
    bool neg_over = x < 0 && y < 0 && sum >= 0;
    return !(pos_over || neg_over);
}

2.77

A

\(x << 4 + x\)

B

\(x - x << 3\)

C

\(x << 6 - x << 2\)

D

\(x << 4 - x << 7\)

2.85

A

E = 2, M = 1.11, f = 11, V = 7.0

B

E = n, M = 1.[1]···, f = [1]···, V = \(2^{n+1} - 1\)

C

E = \(2^{k-1}-2\), M = 1, f = 0, V = \(2^{2^{k-1}-2}\)

2.91

A

11.0010010000111111011011

B

11.[001]···

posted @ 2023-10-25 18:17  dddon  阅读(9)  评论(0编辑  收藏  举报