Chapter3

Chapter3 - Chapter 3: Number Systems EEC 70 Fall 2010...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 3: Number Systems EEC 70 Fall 2010 Professor Wilken 1 Position-Weighted Numbers Base 10 Humans and computers use positionposition weighted numbers, humans use base 10: • There are ten numerals: 0-9 • Each number’s digit is weighted by an additional digit factor of 10, starting with a weight of 1, i.e., 100, for factor for the right digit, the least significant digit least Thus 6789ten represents: 6*103 + 7*102 + 8*101 + 9*100 represents: 2 Base Two Computers use base 2 (binary) numbers Computers • transistors can be On or Off • capacitors can be Charged or Discharged Binary has 2 numerals: 0 and 1 Binary A binary digit is called a bit is bit Each bit in a base 2 number is weighted by an additional factor of 2 by Thus 10110two represents: represents: 1*24 + 0*23 + 1*22 + 1*21 + 0*20 3 Position-Weighted Numbers (cont.) Why do humans use base ten and not eleven (fingers on two hands can represent digits zero thru ten), given that base eleven would be more efficient? base 4 Position-Weighted Numbers (cont.) Any integer can be used as the base for a number system. What other bases do people use or have used? people 5 Babylonian Base 60 System, Sexagesimal Babylonian Basis for modern measure of time and degrees degrees 6 Egyptian/Others Base 12, Duodecimal Egyptian/Others Basis for hours per day (12 for day, 12 for night), inches per foot, other measures night), 12 is a dozen 12 2 122 (144) is a gross 12 (144) gross 3 123 (1728) is a great gross 12 (1728) great 7 Mayan Base 20 System, Vigesimal Based on counting using both hands and feet feet 8 Transforming Between Bases Given an integer X in one base (radix), say base 10, how in can it be transformed into another base, say base 2? can X = Yn*2n + Yn-1*2n-1 + ... + Y2*22 + Y1*21 + Y0*20 We want to determine the unknown binary digits Yi How? Starting with X, repeatedly divide quotient by 2, until repeatedly quotient is 0. Remainder at each step is the next binary digit (starting with LSB) digit [Yn*2n + Yn-1*2n-1 + ... + Y2*22 + Y1*21 + Y0*20] / 2 = Yn*2n-1 + Yn-1*2n-2 + ... + Y2*21 + Y1*20 rem Y0 rem [Yn*2n-1 + Yn-1*2n-2 + ... + Y2*21 + Y1*20] / 2 = Yn*2n-2 + Yn-1*2n-3 + ... + Y2*20 rem Y1 rem 9 Base Transformation Example Let’s convert 6789ten to base 2: Let 6789 / 2 = 3394 rem 1 6789 10 Base Transformation Example Let’s convert 6789ten to base 2: Let 6789 / 2 = 3394 rem 1 6789 3394 / 2 = 1697 rem 0 3394 11 Base Transformation Example Let’s convert 6789ten to base 2: Let 6789 / 2 = 3394 rem 1 6789 3394 / 2 = 1697 rem 0 3394 1697 / 2 = 1697 848 rem 1 12 Base Transformation Example Let’s convert 6789ten to base 2: Let 6789 6789 3394 3394 1697 1697 848 848 424 424 212 212 106 106 53 53 26 26 13 13 6 3 1 / / / / / / / / / / / / / 2 2 2 2 2 2 2 2 2 2 2 2 2 = 3394 rem 1 = 1697 rem 0 = 848 rem 1 = 424 rem 0 = 212 rem 0 = 106 rem 0 = 53 rem 0 = 26 rem 1 = 13 rem 0 = 6 rem 1 = 3 rem 0 rem = 1 rem 1 rem = 0 rem 1 rem Thus 6789ten is 1101010000101two is 1101010000101 13 Converting to Base Two Method II 1. Find the first power of 2 larger than the Find base ten integer base 2. Set the remainder equal to base-ten integer 3. Find the largest power of two that is less Find than or equal to the remainder than • Subtract that power of two from the remainder to Subtract produce a new remainder produce • Set the corresponding digit to 1 • quit if the remainder is zero, else repeat step 3. 14 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 8 1 9 2 0 15 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 – 4096 = 2693 8 1 9 2 4 0 9 6 0 1 16 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 – 4096 = 2693 2693 – 2048 = 645 2693 8 1 9 2 4 0 9 6 2 0 4 8 0 1 1 17 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 – 4096 = 2693 2693 – 2048 = 645 2693 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 0 1 1 0 18 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 – – - 4096 2048 512 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 0 1 1 0 = 2693 = 645 = 133 1 19 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 – – - 4096 2048 512 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 0 1 1 0 1 = 2693 = 645 = 133 0 20 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 – – - 4096 2048 512 128 = 2693 = 645 = 133 = 5 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 0 1 1 0 1 0 1 21 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 – – - 4096 2048 512 128 = 2693 = 645 = 133 = 5 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 6 4 0 1 1 0 1 0 1 0 22 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 – – - 4096 2048 512 128 = 2693 = 645 = 133 = 5 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 6 4 3 2 0 1 1 0 1 0 1 0 0 23 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 – – - 4096 2048 512 128 = 2693 = 645 = 133 = 5 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 6 4 3 2 1 6 0 1 1 0 1 0 1 0 0 0 24 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 – – - 4096 2048 512 128 = 2693 = 645 = 133 = 5 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 6 4 3 2 1 6 8 0 1 1 0 1 0 1 0 0 0 0 25 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 5 – – - 4096 2048 512 128 4 = 2693 = 645 = 133 = 5 = 1 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 6 4 3 2 1 6 8 4 0 1 1 0 1 0 1 0 0 0 0 1 26 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 5 – – - 4096 2048 512 128 4 = 2693 = 645 = 133 = 5 = 1 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 6 4 3 2 1 6 8 4 2 0 1 1 0 1 0 1 0 0 0 0 1 0 27 Example Let’s convert 6789ten to base 2: Let 213 = 8192 is the first larger power of 2 8192 6789 2693 2693 645 645 133 133 5 1 – – - 4096 2048 512 128 4 1 = 2693 = 645 = 133 = 5 = 1 = 0 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6 1 2 8 6 4 3 2 1 6 8 4 2 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 28 Base Transformation Two to Ten Method 1 (for Computers) Repeatedly divide given binary number by ten using binary math (10ten = 1010two). Example: using ). convert 1101010000101two back to base 10 convert 1101010000101two/1010two=1010100110two rem 1001two = rem 9ten rem ten two 1010100110two/1010two= 1010100110 1000011two rem 1000two = rem 8ten rem ten two 1000011two/1010two= 1000011 110two rem 0111two = rem 7ten rem two 110two/1010two = 0two rem 0110two = rem 6ten rem ten two Thus 1101010000101two is 6789ten Thus This method well works for computers, but is it stinks for humans stinks 29 Base Transformation Two to Ten Method 2 (for Humans) Compute the weight of each digit position, add the weights with a “1” digit digit 4 0 9 6 2 0 4 8 1 0 2 4 521 152631 2684268421 1 1 0 1 0 1 0 0 0 0 1 0 1two 1101010000101two = 4096+2048+512+128+4+1 = 6789ten 30 Hexadecimal (base 16) Long binary numbers are tedious for humans e.g., 11010101101110110001011100010010 11010101101110110001011100010010 Hexadecimal (base 16) numbers give a compact Hexadecimal representation that easily translates into/out of binary Binary number can be separated into groups of four digits each: four 1101 0101 1011 1011 0001 0111 0001 0010 Each group has a weight that increases from the right by a factor of 24 = 161. Thus, can replace right Thus, each group of 4 binary digits with a base-16 digit each 16 to form a hex number. to 31 Hexadecimal (cont.) Hex symbols: use decimal symbols for hex digits 0-9, use letters a-f for hex digits with value 10-15 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Hex 0 1 2 3 4 5 6 7 8 9 a b c d e f Convert 1101010110111011two to hex: 1101 0101 1011 1011 d 5 b b 32 Two Common Uses of Hex HTML represents 24-bit color in hex HTML #RRGGBB Media Access Control (MAC) addresses Media (MAC) are presented in hex. are • unique 48-bit number for each network bit adapter adapter • shows manufacturer and serial number: shows manufacturer and serial MM:MM:MM:SS:SS:SS 33 Representing Fractions Moving right from the radix point, each digit radix each weight decreases by one factor of the base weight • Radix point is general term: called decimal point for Radix base 10, binary point for base 2 binary Thus: Thus: 0.5432ten represents: 5*10-1 + 4*10-2 + 3*10-3 +2*10-4 +2 0.10011two represents: 1*2-1 + 0*2-2 + 0*2-3 +1*2-4 +1*2-5 +1 +1 34 Transforming Fraction Between Bases Given a fraction X in one base (e.g. base 10), how to in transform it into another base (e.g., base 2)? transform ... X = Y1*2-1 + Y2*2-2 + Y3*2-3 + Y4*2-4 + ... We want to determine the unknown binary digits Y. Repeatedly multiply fraction by 2, until fraction is 0. Integer part at each step is the next binary digit (starting with fraction’s MSB) (starting [Y1*2-1 + Y2*2-2 + Y3*2-3 + Y4*2-4 + ... ] * 2 = Y1 + Y2*2-1 + Y3*2-2 + Y4*2-3 + ... [Y2*2-1 + Y3*2-2 + Y4*2-3 + ... ] * 2 = ... Y2 + Y3*2-1 + Y4*2-2 + ... 35 Fraction Transformation Numeric Example Let’s convert 0.375ten to base 2: Let 0.375 x 2 = 0.75 0.375 # first digit is 0 36 Fraction Transformation Numeric Example Let’s convert 0.375ten to base 2: Let 0.375 x 2 = 0.75 # first digit is 0.75 0.75 # second digit is 1 x 2 = 1.5 0 37 Fraction Transformation Numeric Example Let’s convert 0.375ten to base 2: Let 0.375 x 2 = 0.75 0.375 # first digit is 0 0.75 0.75 x 2 = 1.5 # second digit is 1 0.5 0.5 x 2 = 1.0 # third digit is 1 Thus 0.375ten is 0.011two 38 Fraction Transformation Precision Decimal fractions with finite digits may require infinite binary Decimal digits for exact representation. digits Let’s convert 0.2ten to base 2: Let 0.2 0.2 0.4 0.4 0.8 0.8 0.6 0.6 x x x x 2 2 2 2 = = = = 0.4 0.8 1.6 1.2 # # # # first digit is next digit is next digit is next digit is 0 0 1 1 0.2 0.2 0.4 0.4 0.8 0.8 0.6 0.6 x x x x 2 2 2 2 = = = = 0.4 0.8 1.6 1.2 # # # # next next next next 0 0 1 1 digit digit digit digit is is is is Thus 0.2ten is 0.0011two Using a finite number of bits, some precision is lost. 39 Transforming Composite Transforming Numbers Numbers How to transform a number from one base to another that consists of an integer and a fractional part? integer 40 Scientific Notation in Different Bases We need a method for representing very small and very large numbers. Examples: large Mass of the earth: 5.98 x 1027 grams 19 Charge of an electron: -1.6 x 10-19 coulombs Charge coulombs Humans use scientific notation, base 10: Humans number = decimal_integer.decimal_fraction x 10decimal_integer 4.78 x 1012 • Decimal_integer is normalized: 1 <= integer < 10 Decimal_integer normalized <= Computers also use scientific notation (called floating point), only it’s with base 2: point number = binary_integer.binary_fraction x 2binary_integer 1.01011 x 21010101 • number is “normalized”: 1 <= integer < 2, i.e., = 1 number • will see floating point details in Chapter 6 41 Transforming Scientific Notation How to transform a number in scientific notation from one base to another? one • We already know how to transform the integer and fraction We parts, need to transform the exponent: parts, x y 10 = 2 x y log1010 = log102 x log1010 = ylog102 x = ylog102 x/log102 = y But y has an integer part and a fractional part. The exponent But in the new number must be an integer. Thus: in w = integer(y) z = y - w z w is the exponent in the new base. 2 is a left over factor is 42 Taylor Series Because computers do not implement z exponentiation in hardware, the 2 exponentiation computation requires a Taylor series computation expansion expansion • Implemented as a math library function using Implemented add, subtract, multiply and divide add, 43 Transforming Scientific Notation Example 330 ten transform N = 1.337 x 10 330 10 to base two y =2 330 / log102 = y y = 1096.2363 0.2363 w = 1096, z = 0.2363, 2 = 1.178 1096 thus N = 1.337 x 1.178 x 2 1096 N = 1.575 x 2 convert integer, fraction and exponent to convert base 2 using previous methods. base methods 44 ...
View Full Document

Ask a homework question - tutors are online