CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett

Slides:



Advertisements
Similar presentations
Number Theory and Cryptography
Advertisements

Binary Addition Rules Adding Binary Numbers = = 1
Computer Arithmetic, Multiplexers Prof. Sin-Min Lee Department of Computer Science.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
CSE 20 DISCRETE MATH Prof. Shachar Lovett Clicker frequency: CA.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
CompSci 102 Discrete Math for Computer Science February 16, 2012 Prof. Rodger.
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
Addition and Substraction
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
Introduction To Number Systems Binary System M. AL-Towaileb1.
Integer Operations Computer Organization and Assembly Language: Module 5.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Unary, Binary, and Beyond Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2003 Lecture 2Jan 16, 2003Carnegie Mellon University.
Unit I From Fundamentals of Logic Design by Roth and Kinney.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
William Stallings Computer Organization and Architecture 8th Edition
Department of Computer Science Georgia State University
Unit 1 Introduction Number Systems and Conversion.
Design of Digital Circuits Reading: Binary Numbers
Introduction To Number Systems
Addition and Subtraction
Recitation3: CS 3843 Computer Organization 4th week
Prof. Sin-Min Lee Department of Computer Science
Digital Logic & Design Adil Waheed Lecture 02.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Chapter 2: Integers and Mathematical Induction
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CHAPTER 1 : INTRODUCTION
Computer Science 210 Computer Organization
CS 232: Computer Architecture II
Logistics Always read the Calendar at
COMPUTING FUNDAMENTALS
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
ITE102 – Computer Programming (C++)
CSE 102 Introduction to Computer Engineering
Integer Representations and Arithmetic
Number Systems.
Number Systems and Bitwise Operation
Addition and Substraction
Binary Addition & Subtraction
ECE 2110: Introduction to Digital Systems
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
Computer Science 210 Computer Organization
SCIENTIFIC NOTATION.
Number Representation
Digital Electronics & Logic Design
Unconventional Fixed-Radix Number Systems
Data Representation in Computer Systems
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Binary / Hex Binary and Hex The number systems of Computer Science.
Digital Logic & Design Lecture 02.
EE207: Digital Systems I, Semester I 2003/2004
UNIVERSITY OF MASSACHUSETTS Dept
Chapter 3 Test Review.
Unit 18: Computational Thinking
COMS 161 Introduction to Computing
CPS120: Introduction to Computer Science
Decimal and binary representation systems
UNIVERSITY OF MASSACHUSETTS Dept
UNIVERSITY OF MASSACHUSETTS Dept
COMS 161 Introduction to Computing
Chapter3 Fixed Point Representation
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
Introduction To Number Systems
Presentation transcript:

CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett

Today’s Topics: Number representations in different bases Converting between bases

1. Number representations all your base are belong to us

Numbers are building blocks Five

Bases Base 𝑏≥2 Number in base b: dkdk-1…d1d0 Digits between 0 and b-1 Number is d0+d1*b+d2*b2+…+dk*bk In every base b, any integer has a unique representation in this base

Values in different bases What’s the decimal value of (10001)2? (5)10 (17)10 (-1)10 (10001)10 None of the above / more than one of the above.

Values in different bases What’s the base 2 representation of the decimal number (42)10? (111111)2 (100001)2 (101010)2 (110011)2 None of the above / more than one of the above.

Values in different bases What’s the biggest integer value whose binary representation has 4 bits? 24 = (16)10 23 = (8)10 (4)10 (1000)10 None of the above / more than one of the above.

Uniqueness Is it possible to have two different representations for an integer in base 2? That is, is it possible to have No. Yes, but m has to be the same as n. Yes, and m,n can be different but for each kind of coefficient that appears in both, it has to agree. That is, a0 = b0, a1 = b1, etc. Yes, if m=n and all the coefficients agree. More than one of the above / none of the above.

Existence and uniqueness Theorem: For any integer 𝑛≥0 and any base 𝑏≥2, there is exactly one way to write n in base b Need to prove existence and uniqueness We will prove for b=2; the proof can be extended to any b

Proof of existence (b=2) Proof by strong induction: Base: n=0 = (0)2 Inductive: assume for all k<n, prove for n Case 1: n is even, n=2k Assume k=(dm … d0)2 Then n=(dm … d0 0)2 Why? Adding a 2 to the right multiplies the number by 2 (shifts all digits by 1)

Proof of existence (b=2) Case 2: n is odd, n=2k+1 Assume k=(dm … d0)2 Then n=(dm … d0 1)2 Why? We already proved that (dm … d0 0)2=2k add 1 to both sides

Proof of uniqueness (b=2) Assume n=(dm…d0)2 = (et…e0)2 Want to prove: must be the same Need to assume that the most significant digits are nonzero, which in binary means they are 1 So assume dm=et=1 We will prove m=t and di=ei for all i

Proof of uniqueness (b=2) Proof by strong induction Base: n=0, only way is (0)2 Inductive: assume for all k<n, prove for n We know least significant digit is n MOD 2, so d0=e0=(n MOD 2) We “peel” the least digit: n DIV 2 = (dm…d1)2 = (et…e1)2 By strong induction, must be the same

Parity and shift

Shifts

Values in different bases What’s the base 2 representation of the decimal number (2014)10 (11111011110)2 (10000000000)2 (10101010101)2 (1000000001)2 None of the above / more than one of the above.

Values in different bases What’s the base 2 representation of the decimal number (2014)10 (11111011110)2 (10000000000)2 (10101010101)2 (1000000001)2 None of the above / more than one of the above. Is there a systematic way (aka algorithm) to do it?

Decimal to Binary conversion toBinary(pos int n) Begin binary=“” i=n While i>0 Do If (i is even) Then binary=“0”+binary End If (i is odd) Then binary=“1”+binary i=i DIV 2 Output binary End. Right to left Questions to ask: Does it always terminate? Does it give the correct answer? What is the time complexity? Biggest power of 2 less than. Recursive. Connect back to RPM.

Other numbers? Fractional components Negative numbers aka how to subtract … first, how do we add? 111 100 1011 1111 Other

One bit addition 1 Carry: 1 0 1 + 1 1 0 1 0 1 1

Subtraction JS p. 6 Borrowing Carrying Complementation A – B = (A – 10) + (10 – B) Carrying A – B = (A+10) – (B+10) Complementation A – B = A + Bc = A + [ (99-B) - 99 ] = A + [ (100-B) – 100 ]

2’s complement How many numbers are we representing with 4 bits? 0000 1111 0001 1110 -1 1 0010 -2 2 1101 0011 -3 3 1100 -4 4 5 -5 -6 6 -7 Complete the wheel of numbers! 7 -8 1001 0111 1000

How to add binary numbers? 1 1 0 0 1 0 1 0 1 +1 0 1 1 0 1 1 0 1 ? ? ? ? ? ? ? ? ? ?

How to add binary numbers? ? ? ? ? ? ? ? ? ? carry 1 1 0 0 1 0 1 0 1 +1 0 1 1 0 1 1 0 1 ? ? ? ? ? ? ? ? ? ?

How to add binary numbers? ? ? ? ? ? ? ? ? ? carry 1 1 0 0 1 0 1 0 1 +1 0 1 1 0 1 1 0 1 ? ? ? ? ? ? ? ? ? ? Two basic operations: One-Bit-Addition(bit1, bit2, carry) Next-carry(bit1, bit2, carry)

Numbers … logic … circuits