Download presentation
Presentation is loading. Please wait.
Published byMargery Mary Jefferson Modified over 9 years ago
1
Review CAS CS210 Ying Ye Boston University
2
Logical expressions Truth table input: A, B, Coutput: D ABCD 0001 1000 1100 1111 0100 0110 0010 1011 (~A)(~B)(~C) ABC A(~B)C D = (~A)(~B)(~C) + ABC + A(~B)C
3
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
4
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. 2 4. b == ? A. 2B. 3C. 6 5. a = b += b++; a == ? A. 2B. 4C. 6 6. b == ? A. 2B. 6C. 5
5
Floating-point numbers 11000000010000000000000000000000 sign bit: 1 Single precision IEEE floating-point format: negative exponent (biased 127): 10000000 value: (10000000) 2 - 127 10 = 1 10 fraction: 10000000000000000000000 value: 1.10000000000000000000000 floating-point number: -1 * (1.1) * 2 1
6
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 0000000. 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?
7
Floating-point numbers +/- X * 2 e Why normalized fraction?.001 * 2 2 =.010 * 2 1 = 0.100 * 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 = 1 + 2 * 4 * 8 1 valid for X = 0 1 free sign bit 2 free fraction bits 3 free exponent bits
8
Practice exam Convert the following binary numbers to hexadecimal: 101111100; 1101; 1011001110011; 110100000100100 Suppose a 7-bit representation. What are the decimal values of the following two’s complement binary numbers? 0001110; 1111000; 1110101
9
Pointer download from http://cs-people.bu.edu/yingy/review.c replace /*TODO*/ with pointer operations, not allowed to use variable a, b except in the first TODO
10
Pointer Output a = 1 b = 2 ++a = 2 a++ = 2 b = 4 a + b = 7
11
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);
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.