1 / 19

Introduction to Computing CS 101 Autumn 2004

Introduction to Computing CS 101 Autumn 2004. Chapter 1 Introduction to Computing. Decimal Number System. Example 3 N = 4790 P = 10 4 – 4790 = 5210 Conclusions Leave least significant 0’s as 0’s Subtract least significant non-zero digit from 10

aliza
Télécharger la présentation

Introduction to Computing CS 101 Autumn 2004

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to ComputingCS 101Autumn 2004

  2. Chapter 1Introduction to Computing

  3. Decimal Number System • Example 3 • N = 4790 • P = 104 – 4790 = 5210 • Conclusions • Leave least significant 0’s as 0’s • Subtract least significant non-zero digit from 10 • Subtract each of the remaining digit from 9 • Compliment of a compliment returns the original number

  4. Decimal Number System • 10’s compliment signed numbers • No signs in 10’s compliment representation • 00  99 represents -50  49 • Smallest number is -50 • Biggest number is 49 • A number is negative if its MSD ≥ 10/2 = 5 • To find magnitude of a negative number, take its 10’s compliment MSD = Most Significant Digit

  5. Decimal Number System • Subtraction using 10’s compliment representation • Compute 35 – 42 • 35 – 42 = (+35) + (-42)  35 + 58 in 10’s compliment • Now 35 + 58 = 93 • 93 is a negative number • 10’s compliment of 93 = 07, so 93 represents -07 • Finally 35 – 42 = -7

  6. Decimal Number System • Subtraction using 10’s compliment representation • Compute 48 – 32 • 48 – 32 = (+48) + (-32)  48 + 68 in 10’s compliment • Now 48 + 68 = 116 • Ignore the 3rd digit, since we are doing two digit arithmetic • 16 is a positive number • Finally 48 - 32 = 16

  7. Decimal Number System • Subtraction using 10’s compliment representation • Compute 35 – 8 • 35 – 8 = (+35) + (-08)  35 + 92 in 10’s compliment • 8 must be represented in 2 digits as 08 (10’s compliment of 8 is 2 in one digit, while 10’s compliment of 08 is 92) • Now 35 + 92 = 127 • Ignore the 3rd digit, since we are doing two digit arithmetic • 27 is a positive number • Finally 35 – 8 = 27

  8. Binary Number System • Base 2 system (2 numbers: 0, 1) • Counting 000001010011100101110111…

  9. Binary Number System Compare with decimal system n zeros

  10. Binary Number System • Expanded form (110010)2 = 1x25 + 1x24 + 1x21 = 32 + 16 + 2 = (50)10 • Addition

  11. Binary Number System • Subtraction (M-N) • Case I: M ≥ N • Case II: M < N • Compute N – M • Multiply answer by -1

  12. Binary Number System • Compliment of a binary number (2’s compliment) • Let N be an n bit number (1010 is 4 bit number) • 2’s compliment of N is given as P = 2n – N • 10000 – 1010 = 0110 • 1s  0s and 0s  1s, except the least significant 1 and lagging 0s’ • Fixed number of bits in a computer • Compute 2’s compliment of 1010 in 8-bit arith. • 0000 1010  1111 0110

  13. Binary Number System • Subtraction using 2’s complement • To evaluate M – N • Write M & N in the same number of bits • Let P = 2’s complement of N • Calculate S = M + P • If there is an “end carry”, discard it. Subtraction is complete • If there is no “end carry”, take 2’s complement of S and associate a negative sign with the result.

  14. Binary Number System • Example • Evaluate the following using 2’s complement. Verify in decimal system. • 1010100 – 1000011  84 – 67 = 17 • M=1010100, N=1000011, P=0111101, S=M+P

  15. Binary Number System • Example • Evaluate the following using 2’s complement. Verify in decimal system. • 1000011 - 1010100  67 - 84 = -17 • M=1000011, N=1010100, P=0101100, S=M+P 2’s compliment

  16. Decimal & Binary conversion • Convert (289)10 into binary • Convert (10111010)2 into decimal • Convert (0.289)10 into binary • Convert (0.10111010)2 into decimal

  17. 2 289 144 1 72 0 36 0 18 0 9 0 4 1 2 0 1 0 Decimal & Binary conversion (289)10 = (1 0010 0001)2

  18. Decimal & Binary conversion • (1011 1010)2 = (?)10 • 1x27 + 1x25 + 1x24 + 1x23 + 1x21 • 128 + 32 + 16 +8 + 2 = 186 • (1011 1010)2 = (186)10

  19. 0.289 X 2 0 0.578 X 2 1 0.156 X 2 0 0.312 X 2 0 0.624 x2 1 0.248 Decimal & Binary conversion • (0.289)10 = (?)2 (0.289)10 = (0.01001…)2 Convert 0.01001 to decimal. (0.01001) 2= 1x2-2 + 1x2-5 = 0.250 + 0.03125 = 0.28125 (0.01001)2 = (0.28125)10

More Related