> 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.58-check-little-endian.md).

# 2.58 Check Little-Endian

★★

**Problem**:

Write a procedure `is_litle_endian` that will return 1 when compiled and run on a little-endian machine, and will return 0 when compiled and run on a big-endian machine. This program should run on any machine, regardless of its word size.

code：

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

typedef unsigned char* byte_pointer;

int is_little_endian() {
    int val = 0xff;
    byte_pointer pval= (byte_pointer)&val;
    return pval[0]==0xff;
}

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

###
