Interview Question

Systems Engineer Interview

how to detect the system is big endian or little endian

Answer

Interview Answer

1 Answer

1

int
is_big_endian ()
{
    int foo;
    char *p;

    foo = 0x12345678;
    p = (char*)& foo;
    if (*p == 0x12) {
        return 1;
    } else {
        /* 0x78 */
        return 0;
    }
}

Brian on Oct 13, 2009

Add Answers or Comments

To comment on this, Sign In or Sign Up.