Todays topics l l l Binary Numbers Brookshear
Today’s topics l l l Binary Numbers Ø Brookshear 1. 1 -1. 6 Slides from Prof. Marti Hearst of UC Berkeley SIMS 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 Compsci 001 3. 1
Digital Computers l l What are computers made up of? Ø Lowest level of abstraction: atoms Ø Higher level: transistors 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 Compsci 001 3. 2
Binary Digits (Bits) l l Yes or No On or Off One or Zero 10010010 Compsci 001 3. 3
More on binary l l l Byte Ø A sequence of bits Ø 8 bits = 1 byte Ø 2 bytes = 1 word (sometimes 4 or 8 bytes) Powers of two How do binary numbers work? Compsci 001 3. 4
Data Encoding l l 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 Numbers: Uses bits to represent a number in base two 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 Compsci 001 3. 5
Images, Sound, & Compression l Images Ø Store as bit map: define each pixel • RGB • Luminance and chrominance Ø Vector techniques • Scalable • True. Type and Post. Script l l Audio Ø Sampling Compression Ø Lossless: Huffman, LZW, GIF Ø Lossy: JPEG, MP 3 Compsci 001 3. 6
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 position: 3 2 3 0 2 1 0 7 2307 = 2 103 + 3 102 + 0 101 + 7 100 Compsci 001 3. 7
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 position: 1101 = Compsci 001 1 20 + 0 2 = 13 1 1 0 1 3 2 1 0 1 23 + + = 1 1 1 22 + 0 21 1 8 = + + 1 4 8+4+1 3. 8
Powers of Two Decimal Compsci 001 Binary Power of 2 1 1 2 10 4 100 8 1000 16 10000 32 100000 64 1000000 128 10000000 3. 9
Famous Powers of Two Compsci 001 Images from http: //courses. cs. vt. edu/~csonline/Machine. Architecture/Lessons/Circuits/index. html 3. 10
Other Number Systems Compsci 001 3. 11 Images from http: //courses. cs. vt. edu/~csonline/Machine. Architecture/Lessons/Circuits/index. html
Binary Addition Also: 1 + 1 = 1 with a carry of 1 Compsci 001 3. 12 Images from http: //courses. cs. vt. edu/~csonline/Machine. Architecture/Lessons/Circuits/index. html
Adding Binary Numbers 101 + 10 ---- 111 l 101 Compsci 001 + 10 = ( 1 22 + 0 21 + 1 20 ) + ( 1 21 + 0 20 ) = 3. 13 (
Adding Binary Numbers 11 carry 111 + 110 ----- ---1101 l 111 + 110 = 1 21 + 0 20 ) ( 1 22 + 1 21 + 1 20 ) + (1 22 + 3. 14 Compsci 001 ( 1 4 + 1 2 + 1 1 ) + (1 4 + 1 2 + 0 1 ) =
Converting Decimal to Binary Decimal 0 1 2 3 4 5 6 7 8 Compsci 001 conversion 0 = 0 20 1 = 1 20 2 = 1 21 + 0 20 3 = 2+1 = 1 21 + 0 20 4 = 1 22 + 0 21 + 0 20 5 = 4+1 = 1 22 + 0 21 + 1 20 6 = 4+2 = 1 22 + 1 21 + 0 20 7 = 4+2+1 = 1 22 + 1 21 + 1 20 8 = 1 22 + 0 21 + 0 20 Binary 0 1 10 11 100 101 110 111 1000 3. 15
Converting Decimal to Binary l Repeated division by two until the quotient is zero l Example: Convert decimal number 54 to binary 1 1 0 1 Binary representation of 54 is 110110 1 0 remainder Compsci 001 3. 16
Converting Decimal to Binary l l 1 l 1 32 = 0 1 l 6 1 32 plus 1 sixteen 0 l 3 16 s = 3 16 plus 0 eights 1 l 13 4 s = 6 8 s plus 1 four 1 l 27 2 s = 13 4 s plus 1 two 0 l 54 8 s = plus 1 thirty-two = 27 2 s plus 0 ones Subtracting highest power of two 54 - 25 = 22 1 s in positions 5, 4, 2, 1 6 - 22 = 2 Compsci 001 22 - 24 = 6 2 - 21 = 0 110110 3. 17
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 Compsci 001 3. 18
Solutions l Convert 1011000 to decimal representation 1011000 = 1 26 + 0 25 + 1 24 + 1 23 + 0 22 + 0 21 + 0 20 = 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 Compsci 001 3. 19
Solutions l Convert 77 to binary representation 1 0 0 1 1 Binary representation of 77 is 1001101 0 1 Compsci 001 3. 20
Boolean Logic l l l AND, OR, NOT, NOR, NAND, XOR 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) 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 Compsci 001 3. 21
Truth Tables Compsci 001 Images from http: //courses. cs. vt. edu/~csonline/Machine. Architecture/Lessons/Circuits/index. html 3. 22
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 Translate 231 in decimal to binary 4. Compsci 001 3. 23
- Slides: 23