Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compsci 001 3.1 Today’s topics l Binary Numbers  Brookshear 1.1-1.6 l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive.

Similar presentations


Presentation on theme: "Compsci 001 3.1 Today’s topics l Binary Numbers  Brookshear 1.1-1.6 l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive."— Presentation transcript:

1 Compsci 001 3.1 Today’s topics l Binary Numbers  Brookshear 1.1-1.6 l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive Introduction to Graph Theory http://www.utm.edu/cgi-bin/caldwell/tutor/departments/math/graph/intro Kearns, Michael. "Economics, Computer Science, and Policy." Issues in Science and Technology, Winter 2005.  Problem Solving

2 Compsci 001 3.2 Digital Computers l What are computers made up of?  Lowest level of abstraction: atoms  Higher level: transistors l Transistors  Invented in 1951 at Bell Labs  An electronic switch  Building block for all modern electronics  Transistors are packaged as Integrated Circuits (ICs)  40 million transistors in 1 IC

3 Compsci 001 3.3 Binary Digits (Bits) l Yes or No l On or Off l One or Zero l 10010010

4 Compsci 001 3.4 More on binary l Byte  A sequence of bits  8 bits = 1 byte  2 bytes = 1 word (sometimes 4 or 8 bytes) l Powers of two l How do binary numbers work?

5 Compsci 001 3.5 Data Encoding l Text: Each character (letter, punctuation, etc.) is assigned a unique bit pattern.  ASCII: Uses patterns of 7-bits to represent most symbols used in written English text  Unicode: Uses patterns of 16-bits to represent the major symbols used in languages world side  ISO standard: Uses patterns of 32-bits to represent most symbols used in languages world wide l Numbers: Uses bits to represent a number in base two l Limitations of computer representations of numeric values  Overflow – happens when a value is too big to be represented  Truncation – happens when a value is between two representable values

6 Compsci 001 3.6 Images, Sound, & Compression l Images  Store as bit map: define each pixel RGB Luminance and chrominance  Vector techniques Scalable TrueType and PostScript l Audio  Sampling l Compression  Lossless: Huffman, LZW, GIF  Lossy: JPEG, MPEG, MP3

7 Compsci 001 3.7 Decimal (Base 10) Numbers l Each digit in a decimal number is chosen from ten symbols: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } l The position (right to left) of each digit represents a power of ten. l Example: Consider the decimal number 2307 2 3 0 7   position: 3 2 1 0 2307 = 2  10 3 + 3  10 2 + 0  10 1 + 7  10 0

8 Compsci 001 3.8 Binary (Base 2) Numbers l Each digit in a binary number is chosen from two symbols: { 0, 1 } l The position (right to left) of each digit represents a power of two. l Example: Convert binary number 1101 to decimal 1 1 0 1   position: 3 2 1 0 1101 = 1  2 3 + 1  2 2 + 0  2 1 + 1  2 0 =1  8 + 1  4 + 0  2 + 1  1= 8 + 4 + 1 = 13

9 Compsci 001 3.9 Powers of Two DecimalBinaryPower of 2 11 210 4100 81000 1610000 32100000 641000000 12810000000

10 Compsci 001 3.10 Famous Powers of Two Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/Circuits/index.html

11 Compsci 001 3.11 Other Number Systems Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/Circuits/index.html

12 Compsci 001 3.12 Binary Addition Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/Circuits/index.html Also: 1 + 1 + 1 = 1 with a carry of 1

13 Compsci 001 3.13 Adding Binary Numbers 101 + 10 -------- 111 l 101 + 10 = ( 1  2 2 + 0  2 1 + 1  2 0 ) + ( 1  2 1 + 0  2 0 ) = ( 1  4 + 0  2 + 1  1 ) + ( 1  2 + 0  1 ) l Add like terms: There is one 4, one 2, one 1 = 1  4 + 1  2 + 1  1 = 111

14 Compsci 001 3.14 Adding Binary Numbers 1 1  carry 111 + 110 --------- 1101 l 111 + 110= ( 1  2 2 + 1  2 1 + 1  2 0 ) + (1  2 2 + 1  2 1 + 0  2 0 ) = ( 1  4 + 1  2 + 1  1 ) + (1  4 + 1  2 + 0  1 ) l Add like terms: There are two 4s, two 2s, one 1 = 2  4 + 2  2 + 1  1 = 1  8 + 1  4 + 0  2 + 1  1 = 1101 l BinaryNumber Applet

15 Compsci 001 3.15 Converting Decimal to Binary Decimal 0 1 2 3 4 5 6 7 8 Binary 0 1 10 11 100 101 110 111 1000   conversion   0 = 0  2 0 1 = 1  2 0 2 = 1  2 1 + 0  2 0 3 = 2+1 = 1  2 1 + 0  2 0 4 = 1  2 2 + 0  2 1 + 0  2 0 5 = 4+1 = 1  2 2 + 0  2 1 + 1  2 0 6 = 4+2 = 1  2 2 + 1  2 1 + 0  2 0 7 = 4+2+1 = 1  2 2 + 1  2 1 + 1  2 0 8 = 1  2 2 + 0  2 2 + 0  2 1 + 0  2 0

16 Compsci 001 3.16 Converting Decimal to Binary l Repeated division by two until the quotient is zero l Example: Convert decimal number 54 to binary  1  0  1  0 Binary representation of 54 is 110110 remainder

17 Compsci 001 3.17 Converting Decimal to Binary l 1 32 = 0 plus 1 thirty-two l 6 8s = 1 32 plus 1 sixteen l 3 16s = 3 16 plus 0 eights l 13 4s = 6 8s plus 1 four l 27 2s = 13 4s plus 1 two l 54 = 27 2s plus 0 ones  1  0  1  0 l Subtracting highest power of two l 1s in positions 5,4,2,1 54 - 2 5 = 22 22 - 2 4 = 6 6 - 2 2 = 2 2 - 2 1 = 0  110110

18 Compsci 001 3.18 Problems l Convert 1011000 to decimal representation l Add the binary numbers 1011001 and 10101 and express their sum in binary representation l Convert 77 to binary representation

19 Compsci 001 3.19 Solutions l Convert 1011000 to decimal representation 1011000 = 1  2 6 + 0  2 5 + 1  2 4 + 1  2 3 + 0  2 2 + 0  2 1 + 0  2 0 = 1  64 + 0  32 + 1  16 + 1  8 + 0  4 + 0  2 + 0  1 = 64 + 16 + 8 = 88 l Add the binary numbers 1011001 and 10101 and express their sum in binary representation 1011001 + 10101 ------------- 1101110

20 Compsci 001 3.20 Solutions l Convert 77 to binary representation  1  0  1  0  1 Binary representation of 77 is 1001101

21 Compsci 001 3.21 Boolean Logic l AND, OR, NOT, NOR, NAND, XOR l Each operator has a set of rules for combining two binary inputs  These rules are defined in a Truth Table  (This term is from the field of Logic) l Each implemented in an electronic device called a gate  Gates operate on inputs of 0’s and 1’s  These are more basic than operations like addition  Gates are used to build up circuits that Compute addition, subtraction, etc Store values to be used later Translate values from one format to another

22 Compsci 001 3.22 Truth Tables Images from http://courses.cs.vt.edu/~csonline/MachineArchitecture/Lessons/Circuits/index.html

23 Compsci 001 3.23 In-Class Questions 1. How many different bit patterns can be formed if each must consist of exactly 6 bits? 2. Represent the bit pattern 1011010010011111 in hexadecimal notation. 3. Translate each of the following binary representations into its equivalent base ten representation. 1. 1100 2. 10.011 4. Translate 231 in decimal to binary


Download ppt "Compsci 001 3.1 Today’s topics l Binary Numbers  Brookshear 1.1-1.6 l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive."

Similar presentations


Ads by Google