360 likes | 559 Views
ECE U322 Digital Logic Design. Lecture 2: Number Representation Conversion between different bases Binary Fractions Unsigned and signed Values Reading: Marcovitz 1-1. Sept. 8, 2005. lect02.ppt. ECE U322 F05. Number Systems. Decimal Numbers (base-10 or radix 10) 8 5 4 . 7 2
E N D
ECE U322Digital Logic Design • Lecture 2: • Number Representation • Conversion between different bases • Binary Fractions • Unsigned and signed Values • Reading: Marcovitz 1-1 Sept. 8, 2005 lect02.ppt ECE U322 F05
Number Systems Decimal Numbers (base-10 or radix 10) 8 5 4 . 7 2 Expanded form: Note: Depending on its position in the string, each digit has an associated value of an integer raised to the power of 10. 2
Notation: A decimal number with n digits to the left of the decimal and m digits to the right of the decimal is represented by a string of coefficients: An-1An-2…A1A0 . A-1A-2…A-m+1A-m Ai is one of 10 digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) • subscript i gives the position of the coefficient and weight 10i. • Decimal numbers are also called base or radix 10. Uses 10 distinct digits. Coefficients are multiplied by powers of 10. 3
Base r Systems • Contains r digits (0, 1, 2, …, r–1 ). • General Form: (expanded or power series form) An-1rn-1 + An-2rn-2 + … + A1r1 + A0r0 + A-1r -1 + A-2r -2 + … + A-m+1r –m+1 + A-mr -m • Positional Notation: An-1An-2…A1A0 . A-1A-2…A-m+1A-m • It is customary to enclose in parentheses with a subscript to indicate base. 4
Example: Base 7 (4215.3)7 • Convert to decimal: (4215.3)7 = 4 x __ + 2 x __ + 1 x __ + 5 x __ + ____ = 1372 + 98 + ___ + ___ + 0.4286 = 1482.4286 5
Binary Numbers (base-2, radix-2) • Digits: 0 and 1 • called bits (Binary digiTs) • Conversion from binary to decimal: (11001.01)2 = _x24 + _x23 + _x22 + _x21 + _x20 + _x2-1 + _x2-2 = = 25.25 (1011.11)2 = = • The number systems popular in computer work are: ____________________________________. 6
Conversion of decimal to binary Base- Base- Steps: Successively subtract powers of two. Let i = 0, the number = N0. • Find the greatest number that is a power of 2 less than Ni. • Niminus this number = Ni+1. • i = i + 1. • Repeat 1 to 3 until Ni+1= 0. • Binary number is obtained from the coefficients of the powers of 2. 1 for positions wherein terms appear in the power series and 0 otherwise. 8
Example: 852 = ( )2 9
Octal and Hexadecimal Numbers Base- Base- • Useful for representing binary quantities indirectly because their bases are______________. • Each octal digit corresponds to _____ binary digits. • Each hexadecimal digit corresponds to _____ binary digits. • Compact representation is convenient. • Most computer manuals use either octal or hexadecimal. • The choice between octal or hex is arbitrary. 10
Compact representation Example: 15 bits would be ___ digits in the octal system. 16 bits would be ___ digits in the hexadecimal system. 15 bits would be ___ digits in the hexadecimal system. 11
Octal Number (base-8, radix-8) • Digits: 0, 1, 2, 3, 4, 5, 6, 7 (375.6)8 = 3x8 + 7x8 + 5x8 + 6x8 = 253.75 12
Hexadecimal Number (base-16, radix-16) • Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F • When r < 10, use the first r digits from the decimal system. • When r > 9, supplement with letters of the alphabet. (E25A)16 = ___x16 + 2x16 + 5x16 + ___x16 = 57946 13
Conversion from Binary to Octal • Partition into groups of three bits each, starting from the binary point, proceeding to the left and to the right. • Convert each group by its corresponding octal digit. Example: ( 11110101000 . 101111 )2 = ( . )8 • Note: • add 0’s to the left of the string of bits to the left of the binary point to make the total count of bits into multiples of three. • add 0’s to the right of the string of bits to the right of the binary point to make the number of bits into multiples of three. Leading zeros Trailing zeros 15
Conversion from Binary to Hexadecimal • Similarly, partition into groups of four bits each, starting from the binary point, proceeding to the left and to the right. • Convert each group by its corresponding hex digit. Example: ( 11110101000 . 101111 )2 = ( . )16 16
Conversion from octal to binary • Reverse the procedure. • Convert each octal digit to a three-bit binary equivalent. • Delete extra 0’s. Example: ( 5 2 3 . 1 2 )8 = ( . )2 = ( . )2 17
Conversion from hexadecimal to binary • Convert each hexadecimal digit to its four-bit binary equivalent. • Delete extra 0’s. Example: ( 7 B F 2 . 9 )16 = ( . )2 = ( . )2 18
Conversion from Decimal to Other Bases • Decimal integer to a number in base r • Divide the number and all successive quotients by r until the result is 0. • Accumulate the remainders from last to first. Ex: Convert decimal 283 to octal. 283/8 = 35 + 3/8 Remainder = 3 = + = = + = (283)10 = ( )8 19
Example: Convert decimal 34 to binary. 34/2 = + Remainder = (34)10 = ( )2 • We can also use the sum of powers of 2 conversion. 34 = 20
Proof: An-1rn-1 + An-2rn-2 + … + A1r1 + A0r0 An-1r + An-2r + … + A1r + A0r An-1r + An-2r + … + A2r + A1r An-1r + An-2r + … + A2r + A1r 21
Conversion of decimal fractions to binary • Multiply the decimal fractions by r until the fractional part becomes 0 or until accuracy is sufficient. • Accumulate the integers from first to last. Ex: Convert decimal 0.6875 to binary. 0.6875 x 2 = 1.3750 Integer = 1 (0.6875)10 = ( )2 22
Note: The process of multiplying fractions by r does not necessarily end with zero, so we must decide how many digits of fraction to use from the conversion. Ex: Convert decimal 0.513 to a three-digit octal fraction. 0.513 x 8 = 4.104 Integer = 4 = 0.832 = = 6.656 = = 5.248 = (0.513)10 = ( )8 23
Proof: A-1r -1 + A-2r -2 + … + A-m+1r -m+1 + A-mr -m A-1r + A-2r + … + A-m+1r + A-mr A-2r -1 + A-3r -2 + … + A-m+1r + A-mr A-2r + A-3r + … + A-m+1r + A-mr 24
Note: To convert numbers with integer and fractional parts, convert each part separately. Ex: (283.513)10 = ( )8 25
Number Ranges • The range of numbers that can be represented is based on the number of bits available in the hardware structures that store and process information. • Frequently, these structures are powers of two, like 8, 16, 32, and 64. • The number of bits available to store numbers is _____. • Fixed structures: • Requires the addition of leading and trailing zeros. • The range of numbers that can be represented is also fixed. 26
Ex: 537 using 16-bit unsigned integers is • 16-bit unsigned integers can represent a range of integers from 0 to ________ or 0 to 65,535 • 16-bit unsigned fraction with binary point to the left of the most significant digit can represent fractions from 0 to_________. 27
1 0 0 0 0 1 1 0 0 1 How to Represent Signed Values? • Use MSB as sign bit: • MSB is 0 value is positive • MSB is 1 value is negative LSB MSB 28
Signed Values • MSB is sign bit • Three methods for interpretting the remaining (non-sign) bits: • sign magnitude • one’s complement • two’s complement 29
Signed Values • Sign Magnitude: • first bit is sign bit, rest is value of number • One’s Complement: • To form a negative number, complement (negate) each bit of the positive number • Two’s Complement: • To form a negative number, take one’s complement, then add 1 • To find value of a negative number, • take two’s complement 31
Signed Values • Positive numbers have the same representation in all three representations ! • S-M and one’s comp have two representations of zero: • this is awkward (especially for comparators) • Two’s complement has unsymmetric range: -8 but no +8 32
Signed Values • Sign Magnitude • useful for multiplication and division • Two’s complement • Useful for addition and subtraction • To subtract A-B, • take two’s comp of B and add to A • We will use two’s complement in this course 33
Values of numbers • What is the value of: 1 1 1 0 0 1 34
1 1 1 0 0 1 Values of numbers • What is the value of: • Two’s complement: • take two’s complement to get value 35
1 1 1 0 0 1 Property of two’s complement • Take two’s complement of 00011: • For any binary number A, • two’s comp( two’s comp A) = A 36