Topics to cover: 0. Role call to get to know names or whatever method you want to use. - My name: Annie Luo - Contact info: (Wean 8402, luluo@cs.cmu.edu) - Office hours: 6-7pm Thursdays. Email/zephyr me to make sure I am in and not busy when you want to stop by. - Know student's name 1. Unix and C: - Quick review of Makefile and how to compile simple program in Unix. (Tab != 8 spaces in Makefile!!) (always use -Wall when compiling!!) - used Makefile from L1 explain how to set target-command pairs - Quick review of how to set up PATH environment etc. - mostly tcsh set setenv crap - from webpage - do bash if necessary - C programming tricks and difference from C++/Java. (program style issue: where declare local variables) (caution on pointers) (C uses printf and scanf, different from C++) - How C is different from C++ - no cout,cin. printf, scanf (make sure to mention scanf requires pointers) - try not to declare local variables in the middle of the code except within { } c thingy - How C is different from Java - pointers!!!!!! - memory allocation / garbage collection (explicit frees for every malloc) - Check who is not comfortable with C. - general programming guidelines - compile with -Wall - all warnings should be fixed 2. Playing with bits - powers of 2. - mentally challenge them up to 216 - hexadecimal (A, B, C, D, E, F) - converting from hexadecimal to binary, vice versa - hexadecimal to decimal and vice versa - clear up two's complement and unsigned number to use 0000 1111 0101 1000 0111 1011 - explain arithmetic and logical right shift - signed integer arithmetic. (but be careful) - unsigned always logical. - ask if they have any questions 3. End with a(some) practice problem(s). - extract a bit - negate some numbers. write a bit string. ~x it. then add 1. point out the pattern - bitParity question int bitParity(int x) /* Problem: return 1 if x contains an odd number of 1s, 0 otherwise. * Operation bound: 20 ops (same ops as in Lab 1) * * Approach: * Can use XOR to evaluate the parity of a 2-bit number. * XOR: the XOR operation evaluates the parity * 2 bits: 0 XOR 1 is 1 (so returns 1 for 01 and 10) * what we want is XOR of all 32 bits of x * too many ops! (31) * Solution: Do things in parallel * * Draw picture of doing XOR by cutting and parallel bit-wise XOR */ int bitParity(int x) { int wd16 = x ^ (x >> 16); int wd8 = wd16 ^ (wd16 >> 8); int wd4 = wd8 ^ (wd8 >> 4); int wd2 = wd4 ^ (wd4 >> 2); int bit = wd2 ^ (wd2 >> 1); return bit & 0x1; }