Review CAS CS210 Ying Ye Boston University
Logical expressions Truth table input: A, B, Coutput: D ABCD (~A)(~B)(~C) ABC A(~B)C D = (~A)(~B)(~C) + ABC + A(~B)C
Logical expressions Properties: expression = NOT( NOT(expression) ) NOT( A AND B) = NOT(A) OR NOT(B) NOT( A OR B) = NOT(A) AND NOT(B) Usage: A AND B = NOT( NOT(A) OR NOT(B) ) A OR B = NOT( NOT(A) AND NOT(B) ) Using constant NOT(A) = A XOR 1
Operators int a, b = 2; 1. a == ? A. 2B. 0C. I don't know 2. a = ++b, b++; a == ? A. 3B. 4C. I don't know 3. a = b += ++b; a == ? A. 3B. 6C b == ? A. 2B. 3C. 6 5. a = b += b++; a == ? A. 2B. 4C b == ? A. 2B. 6C. 5
Floating-point numbers sign bit: 1 Single precision IEEE floating-point format: negative exponent (biased 127): value: ( ) = 1 10 fraction: value: floating-point number: -1 * (1.1) * 2 1
Floating-point numbers use a floating point representation with a sign bit in the leftmost position, followed by a three-bit two’s complement exponent, followed by a normalized three bit fraction in base 2. A normalized fraction means a 1 to the right of the binary point, for example.101 is normalized. Zero is represented by the bit pattern There is no hidden 1. There are a total of seven bits in this floating point representation, and there are 2 7 = 128 unique bit patterns. How many of these bit patterns are valid?
Floating-point numbers +/- X * 2 e Why normalized fraction?.001 * 2 2 =.010 * 2 1 = * 2 0 If X = 0: only 1 valid number If X != 0: the most significant bit of X must be 1, leaving only 2 free bits for fraction total valid number = * 4 * 8 1 valid for X = 0 1 free sign bit 2 free fraction bits 3 free exponent bits
Practice exam Convert the following binary numbers to hexadecimal: ; 1101; ; Suppose a 7-bit representation. What are the decimal values of the following two’s complement binary numbers? ; ;
Pointer download from replace /*TODO*/ with pointer operations, not allowed to use variable a, b except in the first TODO
Pointer Output a = 1 b = 2 ++a = 2 a++ = 2 b = 4 a + b = 7
Pointer Possible solution: int *p1 = &a, *p2 = &b; printf("a = %d\n", *p1); printf("b = %d\n", *p2); printf("++a = %d\n", ++(*p1)); printf("a++ = %d\n", (*p1)++); *p2 = 4; printf("b = %d\n", *p2); printf("a + b = %d\n", *p1 + *p2);