27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

<strong>Solutions</strong> 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 />

pg 82<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

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

Saved successfully!

Ooh no, something went wrong!