cpsc 121 models of computation
play

CPSC 121: Models of Computation Instructor: Bob Woodham - PowerPoint PPT Presentation

CPSC 121: Models of Computation Instructor: Bob Woodham woodham@cs.ubc.ca Department of Computer Science University of British Columbia Lecture Notes 2008/2009, Section 203 CPSC 121: Models of Computation Menu January 12, 2009 Topics:


  1. CPSC 121: Models of Computation Instructor: Bob Woodham woodham@cs.ubc.ca Department of Computer Science University of British Columbia Lecture Notes 2008/2009, Section 203 CPSC 121: Models of Computation

  2. Menu January 12, 2009 Topics: Representing Values Reading: Today: Epp 1.5 January 14: Epp 1.3 Reminders: Labs and tutorials have begun! On-line Quiz 3 deadline 9:00pm January 13 READ the WebCT Vista course announcements board On-line Quiz 2 (any marks ⇒ full marks) On-line/static Quiz 1 (mark has been waived) WebCT Vista: http://www.vista.ubc.ca www: http://www.ugrad.cs.ubc.ca/~cs121/ CPSC 121: Models of Computation

  3. Representing Values In analog devices, data values are continuous quantities, like electric current or voltage In digital devices, values are discrete. Each basic data element takes on one of a finite number of distinct values Modern computers are digital and binary. The basic data element has only two states, representing the binary digits 0 and 1. A binary digit is called a bit Collections of bits are used to represent numbers, characters, and machine instructions Collections of bits also are used to represent drawings, images, video and sound CPSC 121: Models of Computation

  4. Fixed Width Binary Data Computer architectures define fixed width binary data pathways Here, we denote an n bit binary data item whose bits are numbered 0 through n − 1 (from the right). Bit 0 is called the Least Significant Bit (LSB) and bit n − 1 is called the Most Significant Bit (MSB) n−1 2 1 0 MSB LSB Typical values for n today are 8, 16, 32, 64 and even 128 CPSC 121: Models of Computation

  5. Positional Notation Consider the integer 158. The notation “158” is called positional notation in base 10 because the position of each digit represents multiplication by a specific power of 10. That is, 158 represents: 1 × 10 2 + 5 × 10 1 + 8 × 10 0 Consider the binary number 10011110. The notation “10011110” is called positional notation in base 2 when the position of each bit represents multiplication by a specific power of 2. Then, 10011110 represents: 1 × 2 7 + 0 × 2 6 + 0 × 2 5 + 1 × 2 4 + 1 × 2 3 + 1 × 2 2 + 1 × 2 1 + 0 × 2 0 = 128 + 16 + 8 + 4 + 2 = 158 CPSC 121: Models of Computation

  6. Positional Notation (cont’d) In decimal (i.e., base 10), we have the 10 digits 0 through 9. Thus, the number of distinct values we can represent with an n digit decimal number is: 10 n In binary (i.e., base 2), we only have the two binary digits (i.e., bits) 0 and 1. Thus, the number of distinct values we can represent with an n bit binary number is 2 n Numbers written in binary typically have many more “digits” than the identical number written in decimal. Two other number bases, octal and hexadecimal, are used to make the reading and writing of binary numbers more compact CPSC 121: Models of Computation

  7. An Aside: Note that 2 10 = 1 , 024 is approximately equal to 10 3 = 1 , 000 This is the basis for a useful rule of thumb. To estimate the number of binary digits required to represent an n digit decimal integer you divide by 3 and multiple by 10. For example, a 9 digit decimal number would take on the order of 30 bits to represent This also is the source of a common confusion. When you buy a gigabyte of memory, you probably think you’re buying 10 9 bytes. You’re actually getting 2 30 = 1 , 073 , 741 , 824 bytes which is more than 73 megabytes greater than a gigabyte This is one of the few occasions when you actually get more than you pay for! CPSC 121: Models of Computation

  8. Octal Octal (i.e., base 8) uses the 8 digits 0 through 7. The following table lists all 3 bit binary numbers and their octal equivalent binary octal 000 0 001 1 010 2 011 3 100 4 101 5 110 6 111 7 CPSC 121: Models of Computation

  9. Octal (cont’d) It is easy to convert binary to/from octal by collapsing/expanding bits in groups of 3 from the right For example, the binary number 10011110 groups from the right as 10 011 110 which is 236 in octal. In positional notation in base 8 , 236 represents: 2 × 8 2 + 3 × 8 1 + 6 × 8 0 = 128 + 24 + 6 = 158 CPSC 121: Models of Computation

  10. Hexadecimal Hexadecimal (or simply hex) is base 16 and needs 16 digits. Hex uses digits 0 through 9 and letters A through F . The following table lists all 4 bit binary numbers and their hex equivalent binary hexadecimal binary hexadecimal 0000 0 1000 8 0001 1 1001 9 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101 D 0110 6 1110 E 0111 7 1111 F CPSC 121: Models of Computation

  11. Hexadecimal (cont’d) It is easy to convert binary to/from hex by collapsing/expanding bits in groups of 4 from the right For example, the binary number 10011110 groups from the right as 1001 1110 which is 9E in hex. In positional notation in base 16 , 9E represents: 9 × 16 1 + 14 × 16 0 = 144 + 14 = 158 CPSC 121: Models of Computation

  12. Binary Coded Decimal (BCD) Suppose we simply replace each decimal digit with its 4 bit hexadecimal equivalent Example: 158 = 000101011000 BCD Question: How many bits are required to represent an n digit number? Answer: Exactly 4 n NOTE: BCD is an encoding, not a positional notation in a different base CPSC 121: Models of Computation

  13. Binary Coded Decimal (BCD) (cont’d) Pros: Changes are localized. A change of a single decimal digit 1 produces change in at most 4 bits in the BCD representation. To compare, a one digit change from 1023 to 1024 produces an 11 bit change when binary positional notation is used Cons: 6 of 16 (37.5%) values in each 4 bit group are never used. 1 This is wastage How do you design circuits to do arithmetic in this format? 2 NOTE: BCD is not widely used today. But, it was used in early calculators. Can you guess why? CPSC 121: Models of Computation

  14. DNA DNA molecules are made up of four bases: guanine, adenine, thymine and cytosine (denoted respectively as G, A, T and C). Sub-sequences of DNA, called genes, code for proteins Proteins are strings of amino acids. There are 20 different amino acids used in protein synthesis Loosely put, nature uses a nucleotide “number” (base 4) to encode a protein “number” (base 20) There can be no simple 1–to–1 relationship between gene nucleotides and the amino acids of the proteins they encode since: 4 1 4 20 = < 4 2 16 20 = < 4 3 64 20 = > What does nature, in fact, do? CPSC 121: Models of Computation

  15. DNA (cont’d) Triplets of nucleotides are used to translate DNA (and RNA) into the amino acid sequence of the requisite protein. There are 64 possible triplets and only 20 amino acids. All but three of the 64 triplets are used to encode amino acids ASIDE: The remaining three triplets are called stop codons. They don’t encode an amino acid. Instead, they cause the translation to be terminated The encoding is redundant (18 of the 20 amino acids are coded for by more than one triplet). The specific redundancy that occurs helps to make nature robust since it minimizes the extent to which mistakes in the nucleotide sequences in genes can change the functions of the proteins they encode CPSC 121: Models of Computation

  16. Characters Characters are encoded into an 8 bit byte. There are two standard encodings, ASCII and EBCDIC ASCII stands for American Standard Code for Information Interchange. ASCII is the most widely used character encoding EBCDIC stands for Extended Binary Coded Decimal Interchange Code. EBCDIC was widely used by IBM but not widely used elsewhere. It still persists today, mainly on IBM mainframes The International Standards Organization (ISO), has developed a 2 byte–per–character encoding, called Unicode, that includes, for example, cyrillic, Chinese and Japanese character sets. Unicode is the standard character encoding used in the Java programming language CPSC 121: Models of Computation

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend