C, pasted on Aug 8:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 ``` ```/* bit hacks */ #include #define CHAR_BIT 8 int main(void) { /* 1) determine the sign of an integer */ int v; int sign; v = 17; sign = v < 0; printf("%d %d\n", v, sign); v = 0; sign = v < 0; printf("%d %d\n", v, sign); v = -17; sign = v < 0; printf("%d %d\n", v, sign); printf("\n"); v = 17; sign = -(v < 0); printf("%d %d\n", v, sign); v = 0; sign = -(v < 0); printf("%d %d\n", v, sign); v = -17; sign = -(v < 0); printf("%d %d\n", v, sign); printf("\n"); v = 17; sign = v >> (sizeof(int) * CHAR_BIT - 1); printf("%d %d\n", v, sign); v = 0; sign = v >> (sizeof(int) * CHAR_BIT - 1); printf("%d %d\n", v, sign); v = -17; sign = v >> (sizeof(int) * CHAR_BIT - 1); printf("%d %d\n", v, sign); printf("\n"); v = 17; sign = (v > 0) - (v < 0); printf("%d %d\n", v, sign); v = 0; sign = (v > 0) - (v < 0); printf("%d %d\n", v, sign); v = -17; sign = (v > 0) - (v < 0); printf("%d %d\n", v, sign); printf("\n"); /* 2) determine if two integers have the same sign */ int x, y; int f; x = 17; y = 17; f = ((x ^ y) < 0); printf("%d\n", f); x = 17; y = -17; f = ((x ^ y) < 0); printf("%d\n", f); printf("\n"); /* 3) determine the absolute value of w */ int w; unsigned int r; int mask; w = 17; mask = w >> sizeof(int) * CHAR_BIT - 1; r = (w + mask) ^ mask; printf("%x %x %x %d\n", w, mask, w + mask, r); w = -17; mask = w >> sizeof(int) * CHAR_BIT - 1; r = (w + mask) ^ mask; printf("%x %x %x %d\n", w, mask, w + mask, r); return 0; } ```

Output:
 ```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ``` ```17 0 0 0 -17 1 17 0 0 0 -17 -1 17 0 0 0 -17 -1 17 1 0 0 -17 -1 0 1 11 0 11 17 ffffffef ffffffff ffffffee 17 ```