Lecture 2: Logic Bryan Burlingame 31 Aug 2016.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

1 Integral Data Types in C. 2 First lecture response sent out Lots of good questions Some questions will be punted to reading when appropriate 3 statements.
Review Two’s complement
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Professor Jennifer Rexford COS 217
1 Integral Data Types in C Professor Jennifer Rexford
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See: P&H Chapter 2.4, 3.2, B.2, B.5, B.6.
Chapter 2 Bits, Data Types, and Operations. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 2-2 How do we.
1 The Design of C: A Rational Reconstruction Jennifer Rexford.
Computers Organization & Assembly Language
How Computers Work Dr. John P. Abraham Professor UTPA.
PYTHON PROGRAMMING Week 14 – Tuesday. STARTER You need to find out the average of a set of exam marks for a class. You don’t know how many marks there.
CPS120: Introduction to Computer Science Midterm Exam Review.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
PART 2 Data Types 1. Integers 2. 2’s Complement 3. Conversion
1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations.
Lecture 2: Operations Bryan Burlingame 9Sept2015.
Lecture 5: Developing Procedural Thinking (How to think like a programmer) B Burlingame 30 Sept 2015.
Week 8: Decisions Bryan Burlingame 21 October 2015.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
Lecture 1: Course Introduction Overview of Computers and their Applications in MAE B Burlingame 2 September, 2015 Heavily based on work by Dr. Buff Furman,
Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types.
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.
CHAPTER 3: Number Systems
Lecture 1: Course Introduction Overview of Computers and their Applications in MAE B Burlingame 3 February, 2016 Heavily based on work by Dr. Buff Furman,
Lecture 2: Logic Bryan Burlingame 10 Feb Ref: xkcd:
Lecture 3: Developing Procedural Thinking (How to think like a programmer) B Burlingame 16 Feb 2016.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Computer Architecture and Number Systems
ECT 109 Help Bcome Exceptional
Lecture 3: Logic Bryan Burlingame 06 Sept 2017.
DAT10403 CHAPTER 4 COMPUTER ARITHMETIC By Noordiana Kassim
Invitation to Computer Science, C++ Version, Fourth Edition
Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
CSE 220 – C Programming Bitwise Operators.
Lec 3: Data Representation
Hexadecimal, Signed Numbers, and Arbitrariness
Data Representation Binary Numbers Binary Addition
ENEL 111 Digital Electronics
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Instructor: David Ferry
Digital Electronics Jess 2008.
CS1001 Programming Fundamentals 3(3-0) Lecture 2
March 2006 Saeid Nooshabadi
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
Chapter 2 Bits, Data Types & Operations Integer Representation
CISC101 Reminders Your group name in onQ is your grader’s name.
Number Systems Decimal (base 10) { }
Digital Logic & Design Lecture 02.
ECEG-3202 Computer Architecture and Organization
Chapter-3 Operators.
Logic operations.
CPS120: Introduction to Computer Science
COMS 161 Introduction to Computing
Chapter 8 Computer Arithmetic
Number Representation & Operators
CMSC250 Fall 2018 Circuits 1 1.
Notes from Last Class Office Hours: GL Accounts?
COMS 161 Introduction to Computing
Information Representation
CSE 370 – Winter Number syst.; Logic functions- 1
ENEL 111 Digital Electronics
Presentation transcript:

Lecture 2: Logic Bryan Burlingame 31 Aug 2016

Ref: xkcd: www.xkcd.com

Announcements Homework posted Homework 1 due next week E-mail: fall2016@me30.org Lab starts this week

The Plan for Today Binary mathematics Discuss Boolean logic Briefly introduce flowcharts For flowcharts, use a proper graphics program. Visio is the standard, and is in labs Gliffy is online, free, and good enough (http://www.gliffy.com) Don’t use Powerpoint or Word. They are time wasters and SUPER ugly.

Binary Representations Computers only contain two values On/Off (High/Low, 0/1, etc.) Binary number only have two value 0/1 Base 2 numbering system A bit: A number in base 2 (binary digit) How computers do what they do? Humans are the translators The machine just presents information Think, what is a letter? Just a squiggle, humans give meaning

Binary Representations Everything in a PC is encoded in binary Computers are finite, so are their representations RGB for colors 24 bit color (8 bits for red, 8 for green, 8 for blue) TIFF Music Midi – Instrument + note MP3 – Sound waves compressed Cruise Control Voltage level going to an actuator

Binary to Decimal Binary number only have two value 0/1 Base 2 numbering system A bit: A number in base 2 (binary digit) Decimal numbers have ten values 0 – 9 Base ten numbering system Think scientific notation 6.02E23 = 6 * 1023 + 0 * 1022 + 2 * 1021 010101012 = 8510= 1 * 27 + 1 * 26 + 1 * 24 + 1 * 22 + 1 * 20 Range? Largest 8 bit value: 111111112 = 25510 Largest 16 bit value: 11111111111111112 = 6553510

Negative Values Recall: Sign bit 1’s Complement The computer only deals in 0/1 Humans provide context Sign bit The first bit represents sign 11010101 = -213, 01010101 = 213 1’s Complement Flip the bits (change 1’s into 0’s) 10101010 = - 213, 01010101 = 213

Negative Values (Cont) 2’s Complement Take 1’s complement, add one 01010100 Start (8410 in this example) 10101011 Flip bits 10101100 Add one (notice the carries)

Binary to Hexadecimal Hexadecimal (base 16) is a convenient numbering system 0 – 9, A – F (A = 1010, B = 1110, etc Observe 24 = 16, allows four bits (a nyble) to be grouped 11002 = 1210 = 0xC16

Binary to Hexadecimal Convert Binary to Hex 1100001110011111b

Binary to Hexadecimal Convert Binary to Hex 1100 0011 1001 1111 b (grouping 4 bits) 12 3 9 15 d C 3 9 F h C39Fh 12 * 163 + 3 * 162 + 9 * 161 + 15 * 160 = 50,079

Representations Decimal (default) Binary Hexadecimal 108 0’01101100 0x6C 108d 0110 1100b 6Ch 10810 0110 11002 6C16 108 dec 0110 1100 bin 6C hex Group by 3s with a comma Group by 4s with a space or an underbar Generally don’t group Spoken short form

Decimal to binary Many ways, this is how I do it 120 120 < 128, 0 in 7th position 120 > 64, 1 in 6th position 120 – 64 = 56 56 > 32, 1 in 5th position 56 – 32 = 24 24 > 16, 1 in 4th position 24 – 16 = 8 8 = 8, 1 in 3rd position 8 – 8 = 0 Once we hit zero, all other values are zero 0111 1000 Why do I do it this way? It is quick when I don’t have a calculator. Your mileage may vary Binary Decimal 1 10 2 100 4 1000 8 10000 16 100000 32 1000000 64 10000000 128

Decimal to binary Many ways, this is how I do it 120 120 < 128, 0 in 7th position 120 > 64, 1 in 6th position 120 – 64 = 56 56 > 32, 1 in 5th position 56 – 32 = 24 24 > 16, 1 in 4th position 24 – 16 = 8 8 = 8, 1 in 3rd position 8 – 8 = 0 Once we hit zero, all other values are zero 0111 1000 Why do I do it this way? It is quick when I don’t have a calculator. Your mileage may vary Binary Decimal 1 10 2 100 4 1000 8 10000 16 100000 32 1000000 64 10000000 128

Bitshifts (<< Left Shift, >> Right Shift) A bit shift shifts bits in a direction Left shift shifts bits to the left and simulates a multiply of 2 Right shift shifts bits to the right and simulates an integer division of 2 Bits outside the range are lost 23 << 3 = 184 (left shift by 3) 0001 0111 shifted = 1011 1000 23 >> 2 = 5 (right shift by 2) 0000 0101 = 5 (note the last two bits are lost)

Representations Decimal (default) Binary 108 0’01101100 108d 10810 0110 11002 108 dec 0110 1100 bin Group by 3s with a comma Group by 4s with a space or an underbar

Bitwise arithmetic Mimics digital hardware Based on Boolean logic Operates on each bit within a number (i.e. operates bitwise) Many, many hardware peripherals take advantage of bitwise operations Implemented directly in hardware Very fast

True and False Generally, false is zero and true is not-zero Usually, all comparisons which are true generate a 1 (23 > 4) = 1 This comes up a lot!

Binary (Bitwise) And - & 1 X 194 & 225 = 227 Binary And is commonly used with “bitmasks” A binary & used with a bitmask can ensure that a given bit is turned “off” & is shift + 7 1100 0010 (194) & 1110 0001 (225) -------------------------------- 1100 0000 (192)

Binary (Bitwise) Or - | Y | 1 X 194 | 225 = 227 1 X 194 | 225 = 227 Binary OR, is, also, commonly used with “bitmasks” A binary | used with a bitmask can ensure that a given bit is turned “on” | is shift + \ 1100 0010 (194) | 1110 0001 (225) -------------------------------- 1110 0011 (227)

Binary (Bitwise) Xor - ⊕ 1 X 194 ^ 225 = 35 Xors are commonly used to switch the values of selected bits or to test for inequivalence C uses ^ for Xor ^ is shift + 6 1100 0010 (194) ⊕ 1110 0001 (225) -------------------------------- 0010 0011 (35)

Binary (Bitwise) Not (complement) - ~ 1 X 194 ^ 225 = 35 Complements simply flip the bits (turn 0’s into 1’s and 1’s into 0’s) C uses ~ for complement ~ is shift + ` (next to 1) 1100 0010 (194) ~ ---------------------------- 0011 1101 (61)

Order of operations – C & Matlab Operators * / % Multiplication, division, modulo (integer) division + - Addition, subtraction << >> Left bitshift, right bitshift & Bitwise and ^ Bitwise xor | Bitwise or

Boolean Logic And && False True Exclusive Or (Xor) ^^ False True Or ||

Boolean Logic - Examples ( 6 < 14 ) && ( 9 > 5 ) 5 || (19 > 45) && (57 < 108) (My name is Bryan) && (This is ME30) (name == “Bryan”) && (class == “ME30”) ((16 + 45) == 61) ^^ ((49) == (7 * 7)) 42

Flowcharts - 1 Flowcharts A graphical tool that diagrammatically depicts the steps and structure of an algorithm or program Symbol Name/Meaning Meaning Process – Any type of internal operation: data transformation, data movement, logic operation, etc. Connector – connects sections of the flowchart, so that the diagram can maintain a smooth, linear flow Input/Output – input or output of data Terminal – indicates start or end of the program or algorithm Decision – evaluates a condition or statement and branches depending on whether the evaluation is true or false Flow lines – arrows that indicate the direction of the progression of the program

Flow control These Boolean operations are used along with flow control (or branching) statements to control the flow of a program Decisions True False

References Nicholas, P. (1994). Digital Design. Minneapolis/St. Paul: West Publishing Company