25.03.2013 Views

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Solutions to Chapter 16 | Low Level<br />

16 5 Write a program to find whe<strong>the</strong>r a machine is big endian or little endian<br />

SOLUTION<br />

1 #define BIG_ENDIAN 0<br />

2 #define LITTLE_ENDIAN 1<br />

3 int TestByteOrder() {<br />

4 short int word = 0x0001;<br />

5 char *byte = (char *) &word;<br />

6 return (byte[0] ? LITTLE_ENDIAN : BIG_ENDIAN);<br />

7 }<br />

2 4 1<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Knowledge Based<br />

pg 82

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!