Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 1.

Slides:



Advertisements
Similar presentations
EET 1131 Unit 7 Arithmetic Operations and Circuits
Advertisements

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, Java Version, Third Edition.
Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, C++ Version, Third Edition.
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Standard positional representation of numbers:
Assembly Language and Computer Architecture Using C++ and Java
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Operations on data CHAPTER 4.
Binary Representation and Computer Arithmetic
Introduction to Computing Systems from bits & gates to C & beyond Chapter 2 Bits, Data Types & Operations Integer Representation Floating-point Representation.
Dr. Bernard Chen Ph.D. University of Central Arkansas
The Binary Number System
Simple Data Type Representation and conversion of numbers
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
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.
Binary Numbers.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Basic Arithmetic (adding and subtracting)
IT253: Computer Organization
Lecture Overview Introduction Positional Numbering System
Data Representation and Computer Arithmetic
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Basic Arithmetic (adding and subtracting)
CSC 370 (Blum)1 Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter)
1 Ethics of Computing MONT 113G, Spring 2012 Session 1 Digital Circuits, binary Numbers Course webpage:
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
1. Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 2.
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.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Number Representation and Arithmetic Circuits
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Invitation to Computer Science, C++ Version, Fourth Edition
Addition and Subtraction
William Stallings Computer Organization and Architecture 7th Edition
Fundamentals & Ethics of Information Systems IS 201
University of Gujrat Department of Computer Science
Invitation to Computer Science, Java Version, Third Edition
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
Chapter 2 Bits, Data Types & Operations Integer Representation
Data Representation Data Types Complements Fixed Point Representation
Data Representation in Computer Systems
Week 7: Gates and Circuits: PART II
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
ECE 120 Midterm 1 HKN Review Session.
Presentation transcript:

Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 1

Topics Zeroes and Ones Transistor Inverter Transistors to Logic Gates Half Adder Full Adder 4 Bit Adder Numbers: Basic Terms Unsigned Representations Sign and Magnitude One’s Complement Two’s Complement Two’s Complement to Decimal Fractions: Fixed Point Binary Floating Point Numbers 2

Zeroes and Ones (Again, again) Introduced binary representation How a single transistor can form a simple electronic switch (one bit) How binary can be used to represent numbers and symbols Now to build on that... Representing negative and real numbers More complex logical operations How computers add numbers Binary and Logic 3

Logic Logic circuits are the building blocks of computers Boolean values are True/False values – equivalent to the On/Off or 1/0 values of binary Boolean operations take some number true/false inputs, and give a true/false output Binary and Logic 4

A Simple Transistor Inverter Simple inverter circuit If Vin is on, Vout will be off Vin off, Vout on A NOT gate InputOutput Binary and Logic 5

Transistors to Logic Gates Using different circuits of transistors & resistors, a range of basic logic gates can be built up Inverter is a NOT gate 0 input becomes 1 output and vice versa Other gates take two (or more) inputs E.g. AND gate produces 1 output only if both inputs are 1 Binary and Logic 6

NOT AND Input AOutput A ABA∙B _ Binary and Logic 7

OR NOR ABA+B AB ____ Binary and Logic 8

OR  NOT = NOR 9 A B C D ABC = A.B OR Input A Output A NOT C Output D _ NOR

NAND XOR (Exclusive OR) AB ABAB ABA∙B ____ Binary and Logic 10

Building Blocks Combine logic gates into larger circuits Can use NAND or NOR gates as building blocks to build other logic gates, e.g.: NAND is a Universal gate which can make up all other gates. Simplifies construction of chips What does this circuit do? Can you build an OR gate from NAND gates? Binary and Logic 11 A B Q

Binary and Logic 13 The diagram below shows NAND gates used to build another logic gate. Which gate does it build? Join ‘Room ’ in the ‘ Socrative ’ app and give your answer. Week 3 Slide 10 quick quiz

Week 3 Slide 10 quick quiz solution Construct an input / output truth table and verify that it is the same as the gate in your answer. Binary and Logic 14

Half Adder ABCS (Sum) (Carry) Binary and Logic 15

Full Adder AB C in C out S C in C out S Binary and Logic 16

4 Bit Adder Binary and Logic 17

Numbers: Basic Terms Integers: The set of whole numbers, e.g , -2, -1, 0, 1, 2, 3,... Real numbers: Numbers which may have a fractional element, e.g. -3.2, 0.01, 3.14,... Repeating (recurring) numbers: Real number where the fractional element contains infinitely repeating digits, e.g. 1/3 = Irrational Numbers: Numbers with infinitely long non- repeating sequences, eg PI π = Binary and Logic 18

Unsigned Representations Binary and Logic 19 Programming languages such as C or C++ allow developers to use unsigned integers Positive only numbers Range 0 to 2n-1 where n is the number of bits used to represent the number n typically equals 8 (byte), 16, 32 or 64 8 bits unsigned can represent an range: 0 to 2 8 – 1 0 to 256 – 1 0 to bits unsigned can represent an range: 0 to 2 16 – 1 0 to – 1 0 to Negative numbers?

Week 3 Slide 17 quick quiz What range can an unsigned 8 bit number represent? Join ‘Room ’ in the ‘Socrative’ app and give your answer. Binary and Logic 20

Sign and Magnitude Simple approach: Use the first bit of any number to indicate whether it is positive or negative First bit is sign (+ or -) bit, remainder is the magnitude (size) of the number E.g. with 4 bits: 0011 = +3, 1011 = = +0, 1000 = -0 Binary and Logic 21

Week 3 Slide 19 quick quiz What is the range for 8 bit sign & magnitude? Join ‘Room ’ in the ‘Socrative’ app and give your answer. Binary and Logic 22

Problems? Simple arithmetic becomes complicated with sign & magnitude representations E.g. one plus minus one: (-1 10 ) = 1010 = Two representations for zero 0000 and 1000 Extra logic required to test when two numbers are equal, in event both are zero Binary and Logic 23

One’s Complement Positive numbers start with zero For negative number take the complement (opposite) of each bit 3 = 0011 so -3 = 1100 Using 4 bits, find the binary for and What is the result of adding these values? Binary and Logic 24

One’s Complement Still two values for zero: 0000 & 1111 But addition works as it should......almost. Need to carry and add back in if the result overflows: BinaryDecimal Incorrect +1Add carry Correct! Binary and Logic 25

Two’s Complement Converting an eight-bit two's complement number to decimal. To do this, you first check if the number is negative or positive by looking at the sign bit. If it is positive (starts with a 0), simply convert it to decimal. If it is negative (starts with a 1), make it positive by inverting the bits and adding one. Then, convert the result to decimal. The negative of this number is the value of the original binary. 26

Two’s Complement Avoids having two representations for 0 Avoids having to carry extra bit & add back in To get a negative number, invert all the bits then add 1: +3 = 0011 Invert: 1100 Add 1: 1101 = -3 Two’s Complement addition? Binary and Logic 27

Two’s Complement Only one zero: bit: Easy way to find the negative of a number: 0111 = = = = -8 Example 1Example 2 1. Starting from the right, find the first '1' Invert all of the bits to the left of that one Binary and Logic 28

Two’s complement to decimal Leading 1, so a negative number Negate to find the magnitude Solution: Starting from the right, find the first '1' Invert all of the bits to the left of that one Convert to decimal = 25 Binary and Logic 29

Two’s Complement to Decimal What is the decimal number represented by each of the following two’s complement binary numbers: Join Socrative Room and add your answers Binary and Logic 30

Two’s Complement to Decimal solution What is the decimal number represented by each of the following two’s complement binary numbers:              - 1 Binary and Logic 31

Fractions: Fixed Point Binary Decimal point is set at fixed position E.g. With 16 bits, could have 12 bits then point then remaining 4 bits Significance of digits after the point: 2 -1, 2 -2, n ( 1/2, 1/4, 1/8,... ) What are the largest and smallest values that can be stored in an unsigned 16 bit (12.4) representation? 2 12 = 4096,2 -4 = 1/2 4 = Binary and Logic 32

Fixed Point Challenge With 8 bits after the point, binary for: a) = b) = c) = Add your answers to ‘Socrative Room ’ DecimalBinary Binary and Logic 33

Floating Point Numbers Fixed point representations place quite small limits on the size of the largest numbers that can be represented the size of the smallest fraction that can be represented Floating point numbers allow computers to represent both very large and very small numbers but still have issues representing some numbers Binary and Logic 34

Decimal Floating Point Numbers Can represent numbers using a floating point system, in decimal this might be: Significant digits are the mantissa or significand Multiplied by 10 to the power of some exponent here the exponents are 3 and -4 NumberMantissaExponent = x =0.983x10 -4 Binary and Logic 35

IEEE 754: Floating Points Standard binary representation Take any real number – represent in three parts: Sign: The first bit is 0 (positive) or 1 (negative) Exponent: The next n many bits Mantissa: The remaining m bits represent the significant digits of the number Most commonly uses 16, 32 or 64 bits Limited number of bits can represent large range Binary and Logic 36

32 bit IEEE Floating Point A float variable in C/C++ 8 bit exponent is unsigned, but has bias value added – to give a range of Allows for very small or very large numbers SignExponentMantissaBiasPrecision 1 bit8 bits23 bits12724 bit Binary and Logic 37

Special Values The IEEE 754 standard specifies some special values: +0 and -0 Infinities (e.g. 1/0) NaN (Not a Number) – some invalid operations such as 0/0 result in NaN Infinity or NaN results can crash programs that are not prepared to handle such results Binary and Logic 38

Further Reading See Module References section on Blackboard Lots of links PCH, 2.1 – 2.3, 4.1 – 4.3, 4.7 – 4.10 Remainder of Chapters 2 & 4 for interest only Binary and Logic 39

Next Week Required Reading HCW Part 3 Overview (p82-93) Chapter 7 (p94-103) Additional Reading ECS Chapters 6 & 10 Binary and Logic 40

This work by Daniel Livingstone at the University of the West of Scotland is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. Image Credits: Title Image and Transistor Inverter circuit CC-BY-SA Daniel Livingstone, 2011 (Inverter circuit drawn using Klunky) Logic Gates, Half Adder and Full Adder circuits all public domain images, sourced from Wikipedia and Wikimedia Commons 4 Bit Adder, CC-BY-SA en:User:Cburnett, Product names, logos, brands, and other trademarks featured or referred to within the these notes are the property of their respective trademark holders. These notes have been produced without affiliation, sponsorship or endorsement from the trademark holders. Binary and Logic 41