Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,

Similar presentations


Presentation on theme: "Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,"— Presentation transcript:

1 Dale & Lewis Chapter 3 Data Representation

2 Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video, images, graphics, etc. −How do you convert these to 0s and 1s? −How do you store the digital information efficiently?

3 Representing numeric data Representing Natural numbers with a finite number of digits General Property: Number of digitsMinMax n0b n -1 Example: −b=10, n=3000 to 999 −b=2, n=3000 to 111 (equivalent to 0 to 7 in decimal) −b=8, n=3000 to 777 (equivalent to 0 to 511 in decimal) −b=16, n=3000 to FFF (equivalent to 0 to 4,095 in decimal)

4 Representing negative numbers (integers) Basic definition −An integer is a number with no fractional part −Examples: +123-67 Integers (signed natural numbers) −Previously we looked at unsigned numbers, i.e. natural numbers −Need a mechanism to represent both positive and negative numbers −Two schemes: 1) sign-magnitude, 2) complementary representaion

5 Sign-magnitude In binary: −Sign: left-most bit (0 = positive, 1 = negative) −Magnitude: remaining bits Example with 6-bit sign-magnitude representation +5 = 000101-5 = 100101 Ranges in binary UnsignedSign-magnitude # of bitsMinMaxMinMax 101 203-1+1 307-3+3 4015-7+7 5031-15+15 6063-31+31 n02 n -1-(2 n-1 -1) +(2 n-1 -1)

6 Complementary representation Difficulties with Sign-magnitude −Two representations for zero +0 = 000000-0 = 100000 −Arithmetic is awkward, especially subtraction Complementary representation −Positive numbers are represented by their corresponding natural numbers −Negative numbers are represented as very large natural numbers −Subtracting numbers reduces to performing addition operations negative numbers: negative(x) ≡ b n -x

7 Complementary representation negative numbers: negative(x) ≡ b n -x Example: let b = 10 and n = 2 Positive numbersNegative numbers (+0) 00 (+1) 01(-1) 99 (+2) 02(-2) 98 (+3) 03(-3) 97 … (+49) 49(-49) 51 (-50) 50

8 Visualization -49 -50 +49 51 50 49 99 00 01 -1 0 +1 98 99 00 01 02 -2 -1 0 +1 +2 49 +49 50 -50

9 Examples of arithmetic in Ten’s complement -35 plus +25 equals -10 65 plus 25 equals 90  Ten’s complement +17 plus +25 equals +42 17 plus 25 equals 42  Ten’s complement +20 plus -30 equals -10 20 plus 70 equals 90  Ten’s complement -20 plus +30 equals +10 80 plus 30 equals 10 (110)  Ten’s complement

10 Examples of arithmetic in Ten’s complement Subtraction reduces to addition because A – B = A + (-B) +5 05-4 96 + -6 + 94 + +6 + 06 -1 99 +2 02 -2 98-5 95 95 + -4 + 96 - +3 - 03 + 97 -6 94 -8 92 Easy to convert between positive number and its negative counterpart −This conversion can be made efficiently and simplify logic circuitry (we will see how)

11 Two’s complement representation Negative numbers: negative(x) ≡ 2 n -x Used in computers because subtraction reduces to addition  simpler circuits To form a negative number −Start with the positive version of the number −Flip the bits: 0  1 and 1  0 −Add 1 to the number produced in the previous step Same process for conversion back to positive numbers The above steps are an indirect way of carrying our the evaluation of 2 n -x, or more conveniently [(2 n -1)-x]+1

12 Examples of Two’s complement +5 (0101) to -5 (1011) -5 (1011) to +5 (0101) Evaluating 2 n -x is 2 4 -5 = 16-5 = 11 10000 - 101 Or 1011 Evaluating [(2 n -1)-x]+1 is [ ( 2 4 -1)-5]+1 = 15-5+1 = 11 1111 (this way you never borrow) - 101 1010 + 1

13 +2 = 0010 + +3 = +0011 +5 = 0101 -2 = 1110 + +3 = +0011 +1 = 10001 ↑ throw away -2 = 1110 = 1110 +2 = 0010 = 0010 - +3 = -0011 = +1101 -5 = = 11011 -1 = = 1111 ↑ throw away

14 Sample test/exam questions Q: Convert -173 to 12-bit two’s complement representation. Show all your work. A: Step 1: Convert 173 to binary by repeated division by 2 173 ÷ 286 1 1 86 ÷ 243 0 01 43 ÷ 221 1 101 21 ÷ 210 1 1101 10 ÷ 2 5 0 01101 5 ÷ 2 2 1 101101 2 ÷ 2 1 0 0101101 1 ÷ 2 0 110101101

15 Sample test/exam questions Q: Convert -173 to 12-bit two’s complement representation. Show all your work. A: Step 1: Convert 173 to binary by repeated division by 2  10101101 Step 2: Expand answer in Step 1 to 12-bits  000010101101 Step 3: Flip-the-bits and add one  111101010010 + 1 111101010011 Final answer: -173 = 111101010011

16 Sample test/exam questions Q: Convert +173 to 12-bit two’s complement representation. Show all your work. Q: Convert the 12-bit two’s complement number 111101010011 to decimal.


Download ppt "Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,"

Similar presentations


Ads by Google