Lecture 4: Binary. CS442: Great Insights in Computer Science Michael L. Littman, Spring 2006. I-Before-E, Continued



Similar documents
Binary Adders: Half Adders and Full Adders

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Understanding Logic Design

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Chapter 2. Binary Values and Number Systems

The string of digits in the binary number system represents the quantity

Solution for Homework 2

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

2.3 IPv4 Address Subnetting Part 2

Chapter 1: Digital Systems and Binary Numbers

CSI 333 Lecture 1 Number Systems

Figure 8-1 Four Possible Results of Adding Two Bits

Number and codes in digital systems

COMBINATIONAL CIRCUITS

Binary Representation

1. True or False? A voltage level in the range 0 to 2 volts is interpreted as a binary 1.

Classless Subnetting Explained

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Logic in Computer Science: Logic Gates

Combinational circuits

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Basic Logic Gates Richard E. Haskell

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Lecture 11: Number Systems

IP Subnetting and Related Topics A Tutorial by Chris Uriarte <chrisjur@cju.com> Updated April 2001

Binary Numbers. Binary Octal Hexadecimal

Activity 6.7.4: IPv4 Address Subnetting Part 2

NUMBER SYSTEMS. 1.1 Introduction

United States Naval Academy Electrical and Computer Engineering Department. EC262 Exam 1

Decimal Number (base 10) Binary Number (base 2)

Let s put together a Manual Processor

Computer Science 281 Binary and Hexadecimal Review

FORDHAM UNIVERSITY CISC Dept. of Computer and Info. Science Spring, Lab 2. The Full-Adder

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Solution Guide Chapter 14 Mixing Fractions, Decimals, and Percents Together

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

APPENDIX B. Routers route based on the network number. The router that delivers the data packet to the correct destination host uses the host ID.

3201 Computer Networks 2014/2015 Handout: Subnetting Question

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Lecture 8: Binary Multiplication & Division

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Pre-lab Preparation: 1. Read thoroughly and prepare the experiment sheet. 2. You must bring a printed copy of this experiment with you to the lab.

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Classful Subnetting Explained

BINARY CODED DECIMAL: B.C.D.

Logic gates. Chapter. 9.1 Logic gates. MIL symbols. Learning Summary. In this chapter you will learn about: Logic gates

Today s topics. Digital Computers. More on binary. Binary Digits (Bits)

Two's Complement Adder/Subtractor Lab L03

MEP Y9 Practice Book A

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

DNA Data and Program Representation. Alexandre David

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

CSE140: Components and Design Techniques for Digital Systems

Subnetting Examples. There are three types of subnetting examples I will show in this document:

Circuits and Boolean Expressions

TCP/IP Drill Pack. By Donna Warren. Created by Donna P. Warren Revised: 1/2/2012 Page 1 of 19

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Gates, Plexers, Decoders, Registers, Addition and Comparison

To Evaluate an Algebraic Expression

3.Basic Gate Combinations

2011, The McGraw-Hill Companies, Inc. Chapter 3

Lecture N -1- PHYS Microcontrollers

Multipliers. Introduction

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

exclusive-or and Binary Adder R eouven Elbaz reouven@uwaterloo.ca Office room: DC3576

CGN Computer Methods

Activity 1: Using base ten blocks to model operations on decimals

FORDHAM UNIVERSITY CISC Dept. of Computer and Info. Science Spring, The Binary Adder

CSE140 Homework #7 - Solution

Gates, Circuits, and Boolean Algebra

Number of bits needed to address hosts 8

Third Southern African Regional ACM Collegiate Programming Competition. Sponsored by IBM. Problem Set

Systems I: Computer Organization and Architecture

Useful Number Systems

Sistemas Digitais I LESI - 2º ano

Lab 1: Full Adder 0.0

Combinational Logic Design

HOMEWORK # 2 SOLUTIO

CS201: Architecture and Assembly Language

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

Number Representation

Base Conversion written by Cathy Saxton

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Expert Reference Series of White Papers. Simple Tricks To Ace the Subnetting Portion of Any Certification Exam COURSES.

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Simplifying Logic Circuits with Karnaugh Maps

EE360: Digital Design I Course Syllabus

Digital Logic Design. Introduction

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:

Design and Development of Virtual Instrument (VI) Modules for an Introductory Digital Logic Course

Chapter 1. Computation theory

Introduction to the Hewlett-Packard (HP) 10BII Calculator and Review of Mortgage Finance Calculations

Binary Numbering Systems

Transcription:

Lecture 4: Binary CS442: Great Insights in Computer Science Michael L. Littman, Spring 26 I-Before-E, Continued There are two ideas from last time that I d like to flesh out a bit more. This time, let s proceed bottom up.

Bit Equality def equal(bit, bit2): return ((bit and bit2) or (not bit and not bit2)) bit bit2 ND NT NT equal ND R utput True if either bit = True and bit2 = True, or bit = False and bit2 = False (they are equal). Group Equality Now that we can test two bits for equality, we would like to test a group of 5 bits for equality (two alphabetic characters). Two groups are equal if each of their bits are equal: bit = bit, bit = bit, etc. def (char, char2): return (equal(char[],char2[]) and (equal(char[],char2[]) and (equal(char[2],char2[2]) and (equal(char[3],char2[3]) and equal(char[4],char2[4])))))

Equal5 Diagram ND ND ND ND EQUL ND R equal ND char char2 2 3 4 2 3 4 ND ND ND ND ND ND ND ND ND ND ND EQUL EQUL EQUL ND R equal R equal R equal ND ND ND ND ND EQUL ND R equal Gates in EQUL5 inputs (2 groups of 5), output bit. The gate consists of 4 and gates 5 equal gates 2 and, 2 not, or (5 total) Total = 29 gates

Local Exception Check # [False, False, False, True, True] is c # [False, True, False, False, True] is i # [False, False, True, False, True] is e def exception3(x,y,z): ex = ND3((x,[False, False, False, True, True]), (y,[false, True, False, False, True]), (z,[false, False, True, False, True])) ex2 = ND3(not (x, [False, False, False, True, True]), (y,[false, False, True, False, True]), (z, [False, True, False, False, True])) return ex or ex2 triple of letters is an exception if it is equal to cie or *ei where * is not equal to c. Exception3 Diagram x y z EQUL ND ND EQUL EQUL5 EQUL EQUL ND F, F, T, T] F, F, T, T] EQUL T, F, F, T] EQUL ND ND EQUL EQUL5 EQUL EQUL EQUL ND ND ND ND Exception3 T, F, F, T] EQUL ND ND EQUL EQUL5 EQUL EQUL EQUL EQUL ND ND EQUL ND EQUL5 EQUL EQUL EQUL ND ND ND NT ND R EQUL ND ND EQUL EQUL5 EQUL EQUL ND F, T, F, T] F, T, F, T] EQUL ND EQUL ND ND EQUL EQUL5 EQUL EQUL EQUL ND ND

Gates in Exception5 5 inputs (3 groups of 5), output bit. The Exception5 gate consists of 2 and gates, not, or (4 total) 6 gates 29 total basic gates per gate Total = 78 gates. Finally, The Whole Thing # word is 7 groups of 5 bits each # [False, False, False, False, False] is _ def exception(word): ps = exception3([false, False, False, False, False], word[], word[]) p = exception3(word[], word[], word[2]) p = exception3(word[], word[2], word[3]) p2 = exception3(word[2], word[3], word[4]) p3 = exception3(word[3], word[4], word[5]) p4 = exception3(word[4], word[5], word[6]) return ((ps or p) or p) or (p2 or (p3 or p4)) seven-letter word is an exception if any of its 3-letter windows shows an exception.

Exception Diagram F, F, F, F] x yz EQUL5 Exception3 EQUL5 N EQUL5 Exception3 EQUL5 EQUL5 EQUL5 x yz EQUL5 Exception3 EQUL5 N EQUL5 Exception3 EQUL5 EQUL5 EQUL5 R word 2 3 4 5 6 x yz EQUL5 Exception3 EQUL5 N EQUL5 Exception3 EQUL5 EQUL5 EQUL5 R R x yz EQUL5 Exception3 EQUL5 N EQUL5 Exception3 EQUL5 EQUL5 EQUL5 R x yz EQUL5 Exception3 EQUL5 N EQUL5 Exception3 EQUL5 EQUL5 EQUL5 x yz EQUL5 Exception3 EQUL5 N EQUL5 Exception3 EQUL5 EQUL5 EQUL5 R Gates in Exception 35 inputs (7 groups of 5), output bit. The Exception gate consists of 5 or gates 6 exception3 gates 78 total basic gates per gate Total = 73 gates, without breaking a sweat.

Exception Let s try it out. http://www.cs.rutgers.edu/~mlittman/ courses/cs442-6/python/exception.py Counting (Decimal) How do we count? Start at the bottom digit. If it s less than 9, add one to it. If it s equal to nine, make it zero and proceed to the digit to the left. 2 54 9 9 9 8

Counting (Binary) Counting in binary is the same idea. Start at the bottom (rightmost) bit. If it s less than, add one to it. If it s equal to, make it zero and proceed to the bit to the left. Place Values Because of the way counting works, we expand the representation by another bit for each power of 2. 7 6 5 4 3 2 So, is: 64+32+8+=5 2 7 2 6 2 5 2 4 2 3 2 2 2 2 28 64 32 6 8 4 2

Number Magic How does this trick work? http://www.brainbashers.com/games/ number.asp Which Have Your Number? Think of a number from to 3. dd the upper left number from each card your number appears on. It is... 6 7 8 9 8 9 4 5 6 7 2 3 6 7 3 5 7 2 2 22 23 2 3 4 5 2 3 4 5 4 5 9 3 5 24 25 26 27 24 25 26 27 2 2 22 23 8 9 22 23 7 9 2 23 28 29 3 3 28 29 3 3 28 29 3 3 26 27 3 3 25 27 29 3

Conversion To go from decimal to binary, start with the biggest power of 2 no bigger than your number. Write down a. Subtract the power of 2 from your number. Cut the power of 2 in half. If your remaining number is larger than the power of 2, write down a and subtract the power of 2. If not, write down. Repeat by cutting the power of 2 in half (until you get to ). Example: Convert 65 Bigger than: 2 9 = 52. Next power of 2 = 6. 65-52=39. Next power of 2 = 8. Next power of 2 = 256. -8=3 Next power of 2 = 28. Next power of 2 = 4. 39-28=. Next power of 2 = 2. Next power of 2 = 64. 3-2= Next power of 2 = 32. Last power of 2 =. =65

Binary ddition + 5 +78 293 Just like in school: work left to right, carry when needed. ++=, ++ =, ++=, ++= Can check via conversion. ther perations Can also define subtraction (with borrowing), multiplication (simpler since there are only 3 facts: x= x= x=, look familiar?), and long division. Can do bitwise logic operations (and, or, not). ll are quite useful...

ther Number Schemes Can represent negative numbers, often via complements. - = 256- = 255. Fixed-width fractions (for dollar amounts). Floating point representations via exponential notation: a x b. Complex numbers: real and imaginary parts. Implementing ddition Half adder: Takes two bits and a carry and outputs a bit and a carry (addc). dder: dds two 8-bit numbers (discards last carry) (addbyte). def addbyte(x,y): z = []*8 sum7 = addc(x[7],y[7],) z[7] = sum7[] sum6 = addc(x[6],y[6],sum7[]) z[6] = sum6[] sum5 = addc(x[5],y[5],sum6[]) z[5] = sum5[] sum4 = addc(x[4],y[4],sum5[]) z[4] = sum4[] sum3 = addc(x[3],y[3],sum4[]) z[3] = sum3[] sum2 = addc(x[2],y[2],sum3[]) z[2] = sum2[] sum = addc(x[],y[],sum2[]) z[] = sum[] sum = addc(x[],y[],sum[]) z[] = sum[] return z def addc(a,b,c): bit = (a and not b and not c) or (not a and b and not c) or (not a and not b and c) or (a and b and c) carry = (a and b and not c) or (a and not b and c) or (not a and b and c) or (a and b and c) return([carry, bit])

Difference Engine Takes a list of 5 numbers: column from the earlier representation. Produce the next column. def DE(numlist): [a,b,c,d,e] = numlist e2 = e d2 = addbyte(d,e) c2 = addbyte(c,d) b2 = addbyte(b,c) a2 = addbyte(a,b) return [a2,b2,c2,d2,e2] utput of circuit is input of next iteration! a b c d e addbyte addbyte addbyte addbyte DE a b c d e Next Time We now have all the pieces to build a simple, working computer... Each cycle, inputs propagate to outputs, which are copied back to inputs to begin again. We need a language to talk to it in, though. Read Hillis Chapter 3.