The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Purpose of Chapter. External Representation of Information.

Similar documents
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Invitation to Computer Science, C++ Version, Third Edition

Basic data types. Building blocks of computation

Experimental Methods I

MACHINE LEVEL REPRESENTATION OF DATA

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Software and Hardware

Chapter 1. Data Storage Pearson Addison-Wesley. All rights reserved

Data Storage. Slides derived from those available on the web site of the book: Computer Science: An Overview, 11 th Edition, by J.

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

The type of all data used in a C (or C++) program must be specified

Fundamental concepts of Information Technology

Digital Computers and Machine Representation of Data

The type of all data used in a C++ program must be specified

Final Labs and Tutors

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Logic, Words, and Integers

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

UNIT 7A Data Representation: Numbers and Text. Digital Data

CHAPTER 2 - DIGITAL DATA REPRESENTATION AND NUMBERING SYSTEMS

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

Objectives. Connecting with Computer Science 2

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

Variables and Data Representation

Digital Fundamentals

Chapter 2 Bits, Data Types, and Operations

Number System. Introduction. Decimal Numbers

Jianhui Zhang, Ph.D., Associate Prof. College of Computer Science and Technology, Hangzhou Dianzi Univ.

Computer Organization and Levels of Abstraction

Digital Fundamentals

Bits and Bit Patterns

History of Computing. Ahmed Sallam 11/28/2014 1

Computer Science 1000: Part #3. Binary Numbers

NUMBERS AND DATA REPRESENTATION. Introduction to Computer Engineering 2015 Spring by Euiseong Seo

Chapter 1. Digital Systems and Binary Numbers

Bits, Words, and Integers

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Chapter Overview. Welcome to Assembly Language

CHW 261: Logic Design

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Binary. Hexadecimal BINARY CODED DECIMAL

Data Representation 1

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

COMP2121: Microprocessors and Interfacing. Number Systems

Chapter 4. Operations on Data

This podcast will demonstrate a logical approach as to how a computer adds through logical gates.

Computer Organization and Levels of Abstraction

COMP2611: Computer Organization. Data Representation

Number Systems. Both numbers are positive

Memory Addressing, Binary, and Hexadecimal Review

EE292: Fundamentals of ECE

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

SISTEMI EMBEDDED. Basic Concepts about Computers. Federico Baronti Last version:

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That

SE311: Design of Digital Systems

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

1 Digital tools. 1.1 Introduction

DIGITAL SYSTEM DESIGN

Inf2C - Computer Systems Lecture 2 Data Representation

More about Binary 9/6/2016

a- As a special case, if there is only one symbol, no bits are required to specify it.

Agenda EE 224: INTRODUCTION TO DIGITAL CIRCUITS & COMPUTER DESIGN. Lecture 1: Introduction. Go over the syllabus 3/31/2010

A Level Computing. Contents. For the Exam:

Analogue vs. Discrete data

Chapter 4: Computer Codes. In this chapter you will learn about:

CMPS 10 Introduction to Computer Science Lecture Notes

Lecture 2: Number Systems

Introduction to Computer Science (I1100) Data Storage

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

Binary Representation. Jerry Cain CS 106AJ October 29, 2018 slides courtesy of Eric Roberts

1. Which of the following Boolean operations produces the output 1 for the fewest number of input patterns?

Microcomputers. Outline. Number Systems and Digital Logic Review

Chapter 2. Data Representation in Computer Systems

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Integer Representation Floating point Representation Other data types

M1 Computers and Data

CS & IT Conversions. Magnitude 10,000 1,

Digital Systems and Binary Numbers

Data Representation. DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Introduction to Computer Science-103. Midterm

Chapter Overview. Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Printing this Slide Show

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

3 Data Storage 3.1. Foundations of Computer Science Cengage Learning

Why Don t Computers Use Base 10? Lecture 2 Bits and Bytes. Binary Representations. Byte-Oriented Memory Organization. Base 10 Number Representation

CS 101: Computer Programming and Utilization

Course overview. Computer Organization and Assembly Languages Yung-Yu Chuang 2006/09/18. with slides by Kip Irvine

Chapter 2 Data Representations

CSE 1320 INTERMEDIATE PROGRAMMING - OVERVIEW AND DATA TYPES

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

National 5 Computing Science Software Design & Development

Numbering systems. Dr Abu Arqoub

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Boolean algebra. June 17, Howard Huang 1

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Transcription:

The Building Blocks: Binary Numbers, Boolean Logic, and Gates Chapter 4 Representing Information The Binary Numbering System Boolean Logic and Gates Building Computer Circuits Control Circuits CMPUT Introduction to Computing (c) Yngvi Bjornsson Purpose of Chapter Learn how computers represent and store information. Learn why computers represent information that way. Learn what the basic building devices in a computer are, and how those devices are used to store information. Learn how to build more complex devices using the basic devices. CMPUT Introduction to Computing (c) Yngvi Bjornsson 2 External Representation of Information When we communicate with each other, we need to represent the information in an understandable notation, e.g. We use digits to represent numbers. We use letters to represent text. Same applies when we communicate with a computer: We enter text and numbers on the keyboard, The computers displays text, images, and numbers on the screen. We refer to this as an external representation. But how do humans/computers store the information internally? CMPUT Introduction to Computing (c) Yngvi Bjornsson 3

Internal Representation of Information Humans: Internal Text, numbers, images, sounds Text, numbers, sounds Computers:??? Text, numbers, images, sounds Text, numbers, images, sounds Binary Numbers CMPUT Introduction to Computing (c) Yngvi Bjornsson 4 What information do we need to represent? Numbers Integers (234, 456) Positive/negative value (-, -23) Floating point numbers ( 2.345, 3.459) Text Characters (letters, digits, symbols) Other Graphics, Sound, Video, CMPUT Introduction to Computing (c) Yngvi Bjornsson 5 Numbering Systems We use the decimal numbering system digits:,, 2, 3, 4, 5, 6, 7, 8, 9 For example: 2 Why use digits (symbols)? Roman: I (=) V (=5) X (=) L (=5), C(=) XII = 2, Pentium III What if we only had one symbol? IIIII IIIII II = 2 What system do computers use? CMPUT Introduction to Computing (c) Yngvi Bjornsson 6

The Binary Numbering System All computers use the binary numbering system Only two digits:, For example:,, Similar to decimal, except uses a different base Binary (base-2):, Decimal (base-):,, 2, 3, 4, 5, 6, 7, 8, 9 Octal (base-8):,, 2, 3, 4, 5, 6, 7 Hexadecimal (base-6):,, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (A=,..., F=5) What do we mean by a base? CMPUT Introduction to Computing (c) Yngvi Bjornsson 7 Decimal vs. Binary Numbers What does the decimal value 63 stand for? 2 63 6 3 x + 6x + 3x base What does the binary value stand for? 2 2 2 2 x4 + x2 + x base CMPUT Introduction to Computing (c) Yngvi Bjornsson 8 Binary-to-Decimal Conversion Table Decimal Binary 2 3 4 5 6 7 Decimal 8 9 2 3 4 5 Binary Decimal 6 7 8 9 2 2 22 23 Binary Decimal 24 25 26 27 28 29 3 3 Binary CMPUT Introduction to Computing (c) Yngvi Bjornsson 9

Converting from Binary to Decimal What is the decimal value of the binary value? 2 2 2 2 x4 + x2 + x 4 + + = 5 What is the decimal value of the binary value? 2 3 2 2 2 2 x8 + x4 + x2 + x 8 + 4 + 2 + = 4 CMPUT Introduction to Computing (c) Yngvi Bjornsson Bits The two binary digits and are frequently referred to as bits. How many bits does a computer use to store an integer? Intel Pentium PC = 32 bits Alpha = 64 bits What if we try to compute a larger integer? If we try to compute a value larger than the computer can store, we get an arithmetic overflow error. CMPUT Introduction to Computing (c) Yngvi Bjornsson Representing Unsigned Integers How does a 6-bit computer represent the value 4? What is the largest 6-bit integer? = x2 5 + x2 4 + + x2 + x2 = 65,535 CMPUT Introduction to Computing (c) Yngvi Bjornsson 2

Representing Signed Integers How does a 6 bit computer represent the value -4? Sign bit. : + (positive), : - (negative) What is the largest 6-bit signed integer? = x2 4 + x2 3 + + x2 + x2 = 32,767 Problem the value is represented twice! Most computers use a different representation, called two s complement. CMPUT Introduction to Computing (c) Yngvi Bjornsson 3 Representing Floating Point Numbers How do we represent floating point numbers like 5.75 and -43.5? Three step process:. Convert the decimal number to a binary number. 2. Write binary number in normalized scientific notation. 3. Store the normalized binary number. Look at an example: How do we store the number 5.75? CMPUT Introduction to Computing (c) Yngvi Bjornsson 4. Convert decimal to binary (5.75 =?) 2 3 2 2 2 2 2-2 -2 8 4 2 ½ ¼ 4 + + ½ + ¼ = 5.75 5.75 decimal. binary CMPUT Introduction to Computing (c) Yngvi Bjornsson 5

2. Write using normalized scientific notation Scientific notation : ± M x B ±E B is the base, M is the mantissa, E is the exponent. Example: (decimal, base=) 3 = 3 x (e.g. 3 * ) 25 = 2.5 x 3 (e.g. 2.5 * ) Easy to convert to scientific notation:. x 2 Normalize to get the. in front of first (leftmost) digit Increase exponent by one for each location. moves left (decreases if we have to move left). x 2 =. x 2 3 CMPUT Introduction to Computing (c) Yngvi Bjornsson 6 3. Store the normalized number +. x 2 +3 Base 2 implied, not stored Mantissa ( bits) Exponent (6 bits) Assumed binary point CMPUT Introduction to Computing (c) Yngvi Bjornsson 7 Representing Text How can we represent text in a binary form? Assign to each character a positive integer value (for example, A is 65, B is 66, ) Then we can store the numbers in their binary form! The mapping of text to numbers Code mapping Need standard code mappings (why?): ASCII (American Standard Code for Information Interchange) => each letter 8-bits only 256 different characters can be represented (2 8 ) Unicode => each letter 6-bits CMPUT Introduction to Computing (c) Yngvi Bjornsson 8

ASCII Code mapping Table Char Integer Binary Char Integer Binary 32 A 65! 33 B 66 34 C 67 48 x 2 49 y 2 2 5 z 22 CMPUT Introduction to Computing (c) Yngvi Bjornsson 9 Example of Representing Text Representing the word Hello in ASCII Look the value for each character up in the table (Convert decimal value to binary) H e l l o 72 8 8 CMPUT Introduction to Computing (c) Yngvi Bjornsson 2 Representing Other Information We need to represent other information in a computer as well Pictures ( BMP, JPEG, GIF, ) Sound ( MP3, WAVE, MIDI, AU, ) Video ( MPG, AVI, MP4, ) Different formats, but all represent the data in binary form! CMPUT Introduction to Computing (c) Yngvi Bjornsson 2

Why do Computers Use Binary Numbers? Why not use the decimal systems, like humans? The main reason for using binary numbers is: Reliability Why is that? Electrical devices work best in a bistable environment, that is, there are only two separate states (e.g. on/off). When using binary numbers, the computers only need to represent two digits: and CMPUT Introduction to Computing (c) Yngvi Bjornsson 22 Binary Storage Devices We could, in theory at least, build a computer from any device:. That has two stable states (one would represent the digit, the other the digit ) 2. Where the two states are different enough, such that one doesn t accidentally become the other. 3. It is possible to sense in which state the device is in. 4. That can switch between the two states. We call such devices binary storage devices Can you think of any? CMPUT Introduction to Computing (c) Yngvi Bjornsson 23 Transistor The binary storage device computers use is called a transistor: Can be in a stable On/Off state (current flowing through or not) Can sense in which state it is in (measure electrical flow) Can switch between states (takes < billionths of a s second!) Are extremely small (can fit > million/cm 2, shrinking as we speak) Transistors are build from materials called semi-conductors e.g. silicon The transistor is the elementary building block of computers, much in the same way as cells are the elementary building blocks of the human body! CMPUT Introduction to Computing (c) Yngvi Bjornsson 24

Circuit Boards, DIPs, Chips, and Transistors CMPUT Introduction to Computing (c) Yngvi Bjornsson 25 Transistor Conceptual Model Control (Base) In (Collector) Out (Emitter) The control line (base) is used to open/close switch: If voltage applied then switch closes, otherwise is open Switch decides state of transistor: Open: no current flowing through ( state) Closed: current flowing through ( state) CMPUT Introduction to Computing (c) Yngvi Bjornsson 26 Transistors Future Development? Why is this important? Technology improving, allowing us to pack the transistors more and more densely (VLSI, ULSI, ) Can we invent more efficient binary storage devices? Past: Magnetic Cores, Vacuum Tubes Present: Transistors Future:? Quantum Computing? CMPUT Introduction to Computing (c) Yngvi Bjornsson 27

Boolean Logic and Gates Section 4.3 CMPUT Introduction to Computing (c) Yngvi Bjornsson 28 Boolean Logic Boolean logic is a branch of mathematics that deals with rules for manipulating the two logical truth values true and false. Named after George Boole (85-864) An English mathematician, who was first to develop and describe a formal system to work with truth values. Why is Boolean logic so relevant to computers? Direct mapping to binary digits! = true, = false CMPUT Introduction to Computing (c) Yngvi Bjornsson 29 Boolean Expressions A Boolean expression is any expression that evaluates to either true or false. Is the expression +3 a Boolean expressions? No, doesn t evaluate to either true or false. Examples of Boolean expressions: X > X < Y A = 2 > 3 CMPUT Introduction to Computing (c) Yngvi Bjornsson 3

or??? This sentence is false CMPUT Introduction to Computing (c) Yngvi Bjornsson 3 Boolean Operators We use the three following operators to construct more complex Boolean expressions AND OR NOT Examples: X > AND X<25 A= OR B> CMPUT Introduction to Computing (c) Yngvi Bjornsson 32 Truth Table for AND Let a and b be any Boolean expressions, then a b a AND b Examples X> AND X<2 X is and Y is 5 X= AND X>Y CMPUT Introduction to Computing (c) Yngvi Bjornsson 33

Truth Table for OR Let a and b be any Boolean expressions, then a b a OR b Examples X> OR X<2 X= OR X>Y X is and Y is 5 CMPUT Introduction to Computing (c) Yngvi Bjornsson 34 Truth Table for NOT Let a be any Boolean expression, then a NOT a Examples NOT X> NOT X>Y X is and Y is 5 CMPUT Introduction to Computing (c) Yngvi Bjornsson 35 Boolean Operators (cont.) Assume X is and Y is 5. What is the value of the Boolean expression? X= OR X=5 AND Y< (X= OR X=5) AND Y< X= OR (X=5 AND Y<) We should use parenthesis to prevent confusion! CMPUT Introduction to Computing (c) Yngvi Bjornsson 36

Examples of Boolean Expressions Assuming X=, Y=5, and Z=2. What do the following Boolean expressions evaluate to? ((X=) OR (Y=)) AND (Z>X) (X=Y) OR (NOT (X>Z)) NOT ( (X>Y) AND (Z>Y) AND (X<Z) ) ( (X=Y) AND (X=) ) OR (Y<Z) CMPUT Introduction to Computing (c) Yngvi Bjornsson 37 Gates A gate is an electronic device that operates on a collection of binary inputs to produce a binary output. We will look at three different kind of gates, that implement the Boolean operators: AND OR NOT CMPUT Introduction to Computing (c) Yngvi Bjornsson 38 Alternative Notation When we are referring to gates, we use a different notation than when using Boolean expressions: a AND b a b a OR B a + b NOT a a The functionality of the operators is the same, just a different notation. CMPUT Introduction to Computing (c) Yngvi Bjornsson 39

Gates AND, OR, NOT + CMPUT Introduction to Computing (c) Yngvi Bjornsson 4 Constructing an AND Gate CMPUT Introduction to Computing (c) Yngvi Bjornsson 4 Constructing an OR Gate CMPUT Introduction to Computing (c) Yngvi Bjornsson 42

Constructing a NOT Gate CMPUT Introduction to Computing (c) Yngvi Bjornsson 43 Gates vs. Transistors We can build the AND, OR, and NOT gates from transistors. Now we can think of gates, instead of transistors, as the basic building blocks: Higher level of abstraction, don t have to worry about as many details. Can use Boolean logic to help us build more complex circuits. CMPUT Introduction to Computing (c) Yngvi Bjornsson 44 Summary Representing information External vs. Internal representation Computers represent information internally as Binary numbers We saw how to represent as binary data: Numbers (integers, negative numbers, floating point) Text (code mappings as ASCII and Unicode) (Graphics, sound, ) CMPUT Introduction to Computing (c) Yngvi Bjornsson 45

Summary (cont.) Why do computers use binary data? Reliability Electronic devices work best in a bistable environment, that is, where there are only 2 states. Can build a computer using a binary storage device: Has two different stable states, able to sense in which state device is in, and easily switch between states. Fundamental binary storage device in computers: Transistor CMPUT Introduction to Computing (c) Yngvi Bjornsson 46 Boolean Logic Summary (cont.) Boolean expressions are expressions that evaluate to either true or false. Can use the operators AND, OR, and NOT Learned about gates Electronic devices that work with binary input/output. How to build them using transistors. Next we will talk about: How to build circuits using gates! CMPUT Introduction to Computing (c) Yngvi Bjornsson 47