> For the complete documentation index, see [llms.txt](https://valineliu.gitbook.io/deuterium-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valineliu.gitbook.io/deuterium-wiki/reading/cs-jing-dian-shu-ji/csapp-3e-homework-solution/2.-representing-and-manipulating-information/2.62-check-arithmetic-right-shift.md).

# 2.62 Check Arithmetic Right Shift

★★★

**Problem**:

Write a function `int_shifts_arithmetic()` that yields 1 when run on a machine that uses arithmetic shifts for data type `int` and yields 0 otherwise. Your code should work on a machine with any word size. Test your code on several machines.

```c
#include <stdio.h>
#include <assert.h>

int int_shifts_are_arithmetic() {
    int val = -1;
    return !(val ^ (val >> 1));
}

int main() {
    assert(int_shifts_are_arithmetic());
    return 0;
}
```

###
