Positional Notation Consider 101 1015 = ? Binary: Base 2
Total Page:16
File Type:pdf, Size:1020Kb
1/21/2019 CS 362: Computer Design Positional Notation Lecture 3: Number System Review • The meaning of a digit depends on its position in a number. • A number, written as the sequence of digits dndn‐1…d2d1d0 in base b represents the value d * bn + d * bn‐1 + ... + d * b2 + d * b1 + d * b0 Cynthia Taylor n n‐1 2 1 0 University of Illinois at Chicago • For a base b, digits will range from 0 to b‐1 September 5th, 2017 Consider 101 1015 = ? • In base 10, it represents the number 101 (one A. 26 hundred one) = B. 51 • In base 2, 1012 = C. 126 • In base 8, 1018 = D. 130 101‐3=? Binary: Base 2 A. ‐10 • Used by computers B. 8 • A number, written as the sequence of digits dndn‐1…d2d1d0 where d is in {0,1}, represents C. 10 the value n n‐1 2 1 0 dn * 2 + dn‐1 * 2 + ... + d2 * 2 + d1 * 2 + d0 * 2 D. ‐30 1 1/21/2019 Binary to Decimal Decimal to Binary • Use polynomial expansion • Repeatedly divide by 2, recording the remainders. • The remainders form the binary digits of the number. 101102 = • Converting 25 to binary 3410=?2 Hexadecimal: Base 16 A. 010001 • Like binary, but shorter! • Each digit is a “nibble”, or half a byte • Indicated by prefacing number with 0x B. 010010 • A number, written as the sequence of digits dndn‐ C. 100010 1…d2d1d0 where d is in {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}, represents the value D. 111110 n n‐1 2 1 0 dn * 16 + dn‐1 * 16 + ... + d2 * 16 + d1 * 16 + d0 * 16 Hexadecimal to binary 23C16 = ?2 • Each hex digit corresponds directly to four A. 10001 binary digits B. 10111110 • 35AE16 = C. 1000111100 D. 1000011011000 2 1/21/2019 If every hex digit corresponds to 4 binary digits, how many binary digits Negative Numbers: Two’s Complement does an octal digit correspond to? • Flip all the bits and add 1 A. 2 • For n bits, in unsigned version ‐x = 2n –x B. 3 C. 4 D. 5 ‐6 in Two’s Complement Two’s Complement: 11012 = ?10 A. 11110110 A. ‐2 B. 11111001 B. ‐3 C. 11111010 C. ‐4 D. 11111110 D. ‐5 Negating Two’s Compliment The negation of 111100012 is _____2 • To negate any number, flip all the bits and add A. 00001110 1 B. 00001111 C. 00011110 D. 01110001 3 1/21/2019 In n bits, the sum of a number and its Addition negation will be A. 0n…00 • Use the same place‐by‐place algorithm that you use for decimal numbers, but do the arithmetic in the appropriate base B. 1n0n‐1…00 • C. 1 …1 Works in a set number of bits – carry out from n 0 the most significant bit is thrown away D. It will vary Addition and Subtraction 2A5C16 + 38BE16 = ? • Positive and negative numbers are handled in A. 586A the same way. B. 631A • The carry out from the most significant bit is ignored. C. 6986 • To perform the subtraction A ‐ B, compute A + (two's complement of B) 111101102 + 000011002 = ?2 011110012 + 000001112 = ? A. 00000010 A. 01000000 B. 00001100 B. 01111110 C. 11110010 C. 10000000 D. 11111110 D. 11111111 4 1/21/2019 Overflow Overflow can occur when adding • Overflow occurs when an addition or A. Two positive numbers subtraction results in a value which cannot be represented using the number of bits B. Two negative numbers available. C. A positive and a negative number • In that case, the algorithms we have been D. A and B using produce incorrect results. E. All of the above To detect overflow, we should How To Detect Overflow A. Check if the most significant bit is a 1 • On an addition, an overflow occurs if and only if the carry into the sign bit differs from the B. Check if the carry‐out bit is a 1 carry out from the sign bit. • C. Check if the carry‐out bit is different from the Overflow occurs if adding two negative most significant bit numbers produces a positive result or if adding two positive numbers produces a negative result. Reading • Next lecture: Electricity & Transistors – Reading: 3.1‐3.4 • First lab due: Wednesday, January 30th 5.