Recitation 2 15 213 Section F Spring 2006 Jernej Barbic Little Endian to Big Endian 32 bit unsigned integer n 37 224 121 216 80 28 178 Little Endian Big Endian Little Endian to Big Endian Little Endian Big Endian unsigned int LE2BE unsigned int x unsigned int result x 24 x 8 0xFF 16 x 8 0xFF 8 x 24 0xFF return result If then else if condition expression1 else expression2 If then else if condition expression1 else expression2 Rewrite as condition expression1 condition expression2 If then else if condition expression1 else expression2 Rewrite as condition expression1 condition expression2 int abs int x int sign x 31 makes either all one or all zero int neg x x 1 computes x 2 s complement return sign neg x sign x if then else 2 s complement general rule b 231 b b b 2 s complement some examples 0x0 0 0x1 1 0x7FFFFFFF 231 1 largest 32 bit int 0xFFFFFFFF 1 0xFFFFFFFE 2 0x800000000 231 smallest 32 bit int 0x800000001 231 1 Floating point Single precision Note exponent boundary is NOT aligned with byte boundary e g 0xFF7FFFFF has lowest exponent bit zero is normalized v Double precision k 11 n 52 Floating point decision diagram Bias 2k 1 1 E d e z ali x 1 s 21 Bias 0 M rm o n YES de r no YES NO Is M 0 d ize al m NO NaN Is e all 1 s NO Is s 0 YES Is e 0 NO YES E x 1 s 2e Bias 1 M Example 1 4 1 0 2 2 s 0 e 2 Bias 125 M 0 representation 3E800000 Example 2 7 8 1 11 x 2 1 s 1 e 1 Bias 126 M 1100 0 representation 0xBF600000 Example 3 17 1 0001 x 24 s 1 e 4 Bias 131 M 000100 0 representation 0xC1880000 Integer as signed int vs float 3490593 int 0x00354321 3490593 0 float 0x4A550C84 Any correlation in bit patterns Integer as signed int vs float 3490593 int 0x354321 c 3490593 221 1 c So we also have 3490593 0 221 1 c Hence s 0 e 21 Bias 148 M c00 length c 21 Integer as signed int vs float 3490593 int 0x354321 3490593 0 float 0x4A550C84 equal bitstrings Good coding style Consistent indentation Avoid long sequences of commands without a comment Each source file should have an appropriate header Have a brief comment at the beginning of each function Quiz 1 Location blackboard Open book open notes closed computer Available today at 4 30pm Duration 30 minutes You must start it by tomorrow 11 30pm Covers all material so far Don t close your browser while taking the quiz If there are problems please email professor
View Full Document