Binary System and Logical Gates

Slides:



Advertisements
Similar presentations
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Advertisements

Data Representation COE 202 Digital Logic Design Dr. Aiman El-Maleh
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, Java Version, Third Edition.
Invitation to Computer Science, C++ Version, Third Edition
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, C++ Version, Third Edition.
Data Representation Computer Organization &
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, C++ Version, Third & Fourth Edition Spring 2008:
Data Representation COE 205
Connecting with Computer Science, 2e
Assembly Language and Computer Architecture Using C++ and Java
Introduction to Programming with Java, for Beginners
Assembly Language and Computer Architecture Using C++ and Java
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, C++ Version, Third Edition.
Chapter 1 Data Storage. 2 Chapter 1: Data Storage 1.1 Bits and Their Storage 1.2 Main Memory 1.3 Mass Storage 1.4 Representing Information as Bit Patterns.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, C++ Version, Fourth Edition.
Professor Jennifer Rexford COS 217
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 12 Data.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
Chapter 2 Bits, Data Types, and Operations. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 2-2 How do we.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
Dr. Bernard Chen Ph.D. University of Central Arkansas
1 Survey of Computer Science CSCI 110, Spring 2011 Lecture 16 Digital Circuits, binary Numbers.
(2.1) Fundamentals  Terms for magnitudes – logarithms and logarithmic graphs  Digital representations – Binary numbers – Text – Analog information 
Computers Organization & Assembly Language
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
CPSC 171 Introduction to Computer Science Boolean Logic, Gates, & Circuits.
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
CS 1308 – Computer Literacy and the Internet. It’s Not Magic  The goal of the next series of lectures is to show you exactly how a computer works. 
Binary Numbers.
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
Invitation to Computer Science 5th Edition
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Compsci Today’s topics l Binary Numbers  Brookshear l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive.
Invitation to Computer Science 6th Edition Chapter 4 The Building Blocks: Binary Numbers, Boolean Logic, and Gates.
Compsci Today’s topics l Binary Numbers  Brookshear l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive.
Chapter 1 Data Storage © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
THE BINARY SYSTEM.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science,
CS 1308 – Computer Literacy and the Internet Building the CPU.
CPS120: Introduction to Computer Science Midterm Exam Review.
CO5023 Introduction to Digital Circuits. What do we know so far? How to represent numbers (integers and floating point) in binary How to convert between.
CPSC 171 Introduction to Computer Science Binary.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Computer Science: An Overview Eleventh Edition
Invitation to Computer Science, C++ Version, Fourth Edition
Bits, Data Types, and Operations
Lec 3: Data Representation
Everything is a number Everything in a computer memory and on storages is a number. Number  Number Characters  Number by ASCII code Sounds  Number.
Digital Logic and Computer Organization
3.1 Denary, Binary and Hexadecimal Number Systems
Fundamentals & Ethics of Information Systems IS 201
University of Gujrat Department of Computer Science
Invitation to Computer Science, Java Version, Third Edition
Invitation to Computer Science, C++ Version, Third Edition
The Building Blocks: Binary Numbers, Boolean Logic, and Gates
Invitation to Computer Science 6th Edition
Presentation transcript:

Binary System and Logical Gates The foundation of all computing devices are built on Hexadecimal numbers are more convenient for working on hardware.

Objectives After studying, students will be able to: Translate between base-ten and base-two numbers, and represent negative numbers using both sign-magnitude and two’s complement representations Explain how floating-point numbers, character, sounds, and images are represented inside the computer Build truth tables for Boolean expressions and determine when they are true or false Describe the relationship between Boolean logic and computer hardware/circuits

The Binary Numbering System How can an electronic (or magnetic) machine represent information? Key requirements: clear, unambiguous, reliable External representation is human-oriented base-10 numbers keyboard characters Internal representation is computer-oriented base-2 numbers base-2 codes for characters

Invitation to Computer Science, 6th Edition

Two Important Factors Two types of integers: Unsigned: not negative Signed: any numbers: positive, zero, negative The number of bits used to hold the integer 4 bits, 8 bits (1 byte), 2 bytes, 4 bytes, any other sizes It is crucially important for signed integers

Base 2 and base 10 The binary numbering system is a base-2 positional numbering system Base ten: Uses 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Each place corresponds to a power of 10 1,943 = 1 * 103 + 9 * 102 + 4 * 101 + 3 * 100 Base two: Uses 2 digits: 0, 1 Each place corresponds to a power of 2 1101 = 1 * 23 + 1 * 22 + 0 * 21 + 1 * 20 = 13

Conversion Converting from binary to decimal Add up powers of two where a 1 appears in the binary number Converting from decimal to binary Repeatedly divide by two and record the remainder Example, convert 9: 9/2 = 4 remainder 1, binary number = 1 4/2 = 2 remainder 0, binary number = 01 2/2 = 1 remainder 0, binary number = 001 1/2 = 0 remainder 1, binary number = 1001

Binary to decimal (1)

Binary to decimal (2) Binary number 10011011

Binary to decimal (3) Binary number 10011011

Binary to decimal (4) Binary number 10011011

Binary to decimal (5) Binary number 10011011

Decimal to Binary (1) Decimal number 156

Decimal to Binary (2) Decimal number 156

Decimal to Binary (3) Decimal number 156

Decimal to Binary (4) Decimal number 156

Arithmetic operations Computers use fixed-length binary numbers for integers, e.g., with 4 bits could represent 0 to 15 Arithmetic overflow: when computer tries to make a number that is too large, e.g. 14 + 2 with 4 bits Binary addition: 0+0=0, 0+1=1, 1+0=1, 1+1=0 with carry of 1 Example: 0101 + 0011 = 1000 Invitation to Computer Science, 6th Edition

Signed integers Signed integers include negative numbers Method I: Sign/magnitude notation uses 1 bit for sign, the rest for value. +5 = 0101, -5 = 1101 0 = 0000 and 1000! Two expressions for 0. No Good!

Signed integers Method II: Two’s complement The MSB bit is a sign bit: 0 --- positive number 1 --- negative number Steps: flip every bit Add 1 +5 = 0101, -5 = 1010 + 1 = 1011 0 = 0000, -0 = 1111 + 1 = 0000

Two’s Complement Determine number of bits used to hold the number The most significant bit (the left-most bit) is the sign bit. 0: positive; 1: negative Bits flip and add 1

Two’s Complement: B to D Interpret 11011011 as a two's complement binary number, and give its decimal equivalent. Notice we use 8 bits. First, note that the number is negative, since it starts with a 1. Change the sign to get the magnitude of the number. 1 1 0 1 1 0 1 1 ¬ 0 0 1 0 0 1 0 0 + 1 ---------------- 0 0 1 0 0 1 0 1 Convert the magnitude to decimal: 001001012 = 2516 = 2×16 + 5 = 3710. Since the original number was negative, the final result is -37.

Two’s Complement: D to B Convert the magnitude, -72 to 8-bit binary 72 --- 01001000 Conversion: 0 1 0 0 1 0 0 0 ¬ 1 0 1 1 0 1 1 1 + 1 --------------- 1 0 1 1 1 0 0 0

Binary Numbers: Using 3 bits 000 ------------ 0 001 ------------ 1 010 ------------ 2 011 ------------ 3 100 ------------ -4 101 ------------ -3 110 ------------ -2 111 ------------ -1

Binary Numbers: -1 3 bits: 111 ------------ -1

Overflow If a location is too small for a number, overflow occurs. for unsigned integers, a byte can hold a number between 0 and 255. If using one byte to store 256, we get 0. For signed integers, a byte can hold a number between -128 and 127. If using one byte to store -130 or 128, overflows occurs.

Hexadecimal Numbers Based on 16 The 16 digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Examples: Hexadecimal Binary Decimal 1 1 1 F 1111 15 11 00010001 17 ff 11111111 255

Hexadecimal Numbers Hexadecimal Binary Decimal 1 0001 1 2 0010 2 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 A 1010 10 B 1011 11 C 1100 12 D 1101 13 E 1110 14 F 1111 15

Hexadecimal Numbers Decimal to hexadecimal: repeatedly divide the decimal number by 16 Hexadecimal to decimal: Right most number + 16 * second number from the right + 256*third number from the right + …

Hexadecimal Numbers Large binary number to decimal number through hexadecimal number: Group the binary number into groups of 4 digits starting from right. Convert each group into a hexadecimal digit Convert the hexadecimal number to decimal.

Hexadecimal Numbers Large decimal number to binary number through hexadecimal number: Convert the decimal number to hexadecimal number Convert each digit of the hexadecimal number into corresponding 4 digits

Floating numbers (optional) Floating point numbers use binary scientific notation Scientific notation, base 10: 1.35 × 10-5 Base 2: 3.2510 = 11.012 = 1.101 × 21 Characters and text: map characters onto binary numbers in a standard way ASCII (8-bit numbers for each character) Unicode (16-bit numbers for each character)

The Binary Numbering System Conversion from binary numbers to decimal: adding exponentials Using 4 bits to represent a binary number Binary number Decimal 0000 --- 0 0001 --- 1 0010 --- 2 0011 --- 3 0100 --- 4 … 0111 --- 7 unsigned signed 1000 --- 8 -8 (8 – 16) 1001 --- 9 -7 (9 – 16) 1111 --- 15 -1 (15 – 16)

The Binary Numbering System Conversion from decimal numbers to binary: recursively division by 2: 10, 20, 50, -40 Operations of binary operations Addition Carry Overflow

Sounds and Images Sounds and images require converting naturally analog representations to digital representations Sound waves characterized by: amplitude: height of the wave at a moment in time period: length of time until wave pattern repeats frequency: number of periods per time unit

Digitization Digitize: to convert to a digital form Sampling: record sound wave values at fixed, discrete intervals To reproduce sound, approximate using samples Quality determine by: Sampling rate: number of samples per second More samples = more accurate wave form Bit depth: number of bits per sample More bits = more accurate amplitude

Images Image sampling: record color or intensity at fixed, discrete intervals in two dimensions Pixels: individual recorded samples RGB encoding scheme: Colors are combinations of red, green, and blue One byte each for red, green, and blue Raster graphics store picture as two-d grid of pixel values

Digitizatin Data size: how much to store: 1000 integer values 10-page text paper 60-second sound file 480 by 640 image Data compression: storing data in a reduced- size form to save space/time Lossless: data can be perfectly restored Lossy: data cannot be perfectly restored

The Binary Numbering System Computers use binary because “bistable” systems are reliable current on/off magnetic field left/right

Transistors Transistors Solid-state switches Change on/off when given power on control line Extremely small (billions per chip) Enable computers that work with gigabytes of data

Boolean Logic and Gates Boolean logic: rules for manipulating true/false Boolean expressions can be converted to circuits Hardware design/logic design pertains to the design and construction of new circuits Note that 1/0 of binary representations maps to true/false of Boolean logic Boolean expressions: x ≤ 35, a = 12 Boolean operators: (0 ≤ x) AND (x ≤ 35), (a = 12) OR (a = 13), NOT (a = 12) (0 ≤ x)  (x ≤ 35), (a = 12) + (a = 13), ~(a = 12)

Boolean Logic and Gates (continued) Truth tables lay out true/false values for Boolean expressions, for each possible true/false input Example: (a  b) + (a  ~b) a b ~b (a  b) (a  ~b) (a  b) + true false

Boolean Logic and Gates (continued) Gate: an electronic device that operates on inputs to produce outputs Each gate corresponds to a Boolean operator

Boolean Logic and Gates (continued) Gates are built from transistors NOT gate: 1 transistor AND gate: 3 transistors OR gate: 3 transistors NAND and NOR: 2 transistors

Building Computer Circuits Circuit: has input wires, contains gates connected by wires, and has output wires Outputs depend only on current inputs: no state

Building Computer Circuits To convert a circuit to a Boolean expression: Start with output and work backwards Find next gate back, convert to Boolean operator Repeat for each input, filling in left and/or right side To convert a Boolean expression to a circuit: Similar approach To build a circuit from desired outcomes: Use standard circuit construction algorithm: e.g., sum-of-products algorithm Invitation to Computer Science, 6th Edition

Building Computer Circuits (continued) Example from text Build truth table: a b c Output1 Output2 1 Invitation to Computer Science, 6th Edition

Building Computer Circuits (continued) Example from text Find true rows for Output1 a b c Output1 Output2 1 Invitation to Computer Science, 6th Edition

Building Computer Circuits Example from text For each true row, AND input sto make 1 a = 0, b = 1, c = 0: (~a  b  ~c) a = 1, b = 1, c = 0: (a  b  ~c) Combine row subexpressions with OR (~a  b  ~c) + (a  b  ~c) Build circuit from expression (and repeat for other output) Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Building Computer Circuits (continued) Compare-for-equality (CE) circuit Input is two unsigned binary numbers Output is 1 if inputs are identical, and 0 otherwise Start with one-bit version (1-CE) and build general version from that Invitation to Computer Science, 6th Edition

Building Computer Circuits (continued) 1-CE circuit: compare two input bits for equality Truth table: Boolean expression: (a  b) + (~a  ~b) a b Output 1 Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Building Computer Circuits (continued) N-bit CE circuit Input: a0a2…an-1 and b0b2…bn-1, where ai and bi are individual bits Pair up corresponding bits: a0 with b0, a1 with b1, etc. Run a 1-CE circuit on each pair AND the results Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Building Computer Circuits Full adder circuit Input is two unsigned N-bit numbers Output is one unsigned N-bit number, the result of adding inputs together Example: Start with one-bit adder (1-ADD) 1 + Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Building Computer Circuits (continued) Sum digit, si, has Boolean expression: (~ai  ~bi  ci) + (~ai  bi  ~ci) + (ai  ~bi  ~ci) + (ai  bi  ci) Carry digit, ci+1, has Boolean expression: (~ai  bi  ci) + (ai  ~bi  ci) + (ai  bi  ~ci) + (ai  bi  ci) Invitation to Computer Science, 6th Edition

Building Computer Circuits (continued) N-bit adder circuit Input: a0a2…an-1 and b0b2…bn-1, where ai and bi are individual bits a0 and b0 are least significant digits: ones place Pair up corresponding bits: a0 with b0, a1 with b1, etc. Run 1-ADD on a0 and b0, with fixed carry in c0 = 0 Feed carry out c1 to next 1-ADD and repeat Invitation to Computer Science, 6th Edition

Control Circuits Control circuits make decisions, determine order of operations, select data values Multiplexor selects one from among many inputs 2N input lines N selector lines 1 output line Each input line corresponds to a unique pattern on selector lines That input value is passed to output Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Control Circuits (continued) Decoder sends a signal out only one output, chosen by its input N input lines 2N output lines Each output line corresponds to a unique pattern on input lines Only the chosen output line produces 1, all others output 0 Invitation to Computer Science, 6th Edition

Control Circuits (continued) Decoder circuit uses To select a single arithmetic instruction, given a code for that instruction Code activates one output line, that line activates corresponding arithmetic circuit Multiplexor circuit uses To choose one data value from among a set, based on selector pattern Many data values flow into the multiplexor, only the selected one comes out Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Invitation to Computer Science, 6th Edition

Summary Computers use binary representations because they maximize reliability for electronic systems Many kinds of data may be represented at least in an approximate digital form using binary values Boolean logic describes how to build and manipulate expressions that are true/false We can build logic gates that act like Boolean operators using transistors Circuits may be built from logic gates: circuits correspond to Boolean expressions Invitation to Computer Science, 6th Edition

Summary Sum-of-products is a circuit design algorithm: takes a specification and ends with a circuit We can build circuits for basic algorithmic tasks: Comparisons (compare-for-equality circuit) Arithmetic (adder circuit) Control (multiplexor and decoder circuits) Invitation to Computer Science, 6th Edition

Pseudo language Pseudo language Step Operation Step 1 operation 1 …… Step N operation N

Pseudo language Input Output Get value(s) of var1(, var2,…) Print value(s) of var1(, var2,…)

Pseudo language Processing Computation Conditional Set the value of “variable” to “arithmetic expression” Conditional If “condition” is true then fist set of operations else second set of opeations

Pseudo language Processing Computation Conditional Set the value of “variable” to “arithmetic expression” Conditional if “condition” is true then fist set of operations else second set of opeations Using indentations

Pseudo language Processing/computation (cont.) Iterative (Loops) While (condition) do step I through step j Steps i: operation … Step j operation [ End of the loop ] --- optional

Pseudo language & Examples The calculation of gas mileage Get the value for gallons used, starting mileage, ending mileage Set the value of distance driven to (ending mileage – starting mileage) Set the value of gas mileage to (distance driven / gallons used) Print the value of gas mileage [ Stop ] --- optional

Pseudo language & Examples Computing the sum of first N integers Get the value of N Set sum to 0, count to 0 While count is <= N do step 4 to 5 Set the sum to (sum + count) Set the value of count to (count + 1) Print the value of sum

Pseudo language & Examples Get the value of largest of n numbers Get the value of n and values of numbers T1 T2…Tn Set the value of largest to the value of T1 Set the value of i to 2 While i is <= n do step 4 to 5 If the value of Tn is larger than the value of largest then Set the value largest to the value of Tn Set the value of i to (i + 1) Print the value of largest

Pseudo language & Examples Sort n numbers: discussing in class Sequential sort Quick sort Search: discussing in class Sequential search Binary search

Efficiency of an Algorithm The Efficiency of an Algorithm is calculated by the computations (arithmetic operations, comparisons…) needed to complete the rask Usually the variable is the magnitude of the task. For example, the size of the array O(1), O(log(n)), O(n), O(n2), …,O(en)…