1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.

Slides:



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

HEXADECIMAL NUMBERS Code
Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
Number Systems Discussion D4.1 Appendix C. Number Systems Counting in Binary Positional Notation Hexadecimal Numbers Negative Numbers.
ECE 331 – Digital System Design
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
Sistemas Digitais I LESI - 2º ano Lesson 2 - Number Systems U NIVERSIDADE DO M INHO E SCOLA DE E NGENHARIA Prof. João Miguel Fernandes
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Number Systems and Codes Discussion D4.1. Number Systems Counting in Binary Positional Notation Hexadecimal Numbers Negative Numbers.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
Introduction to Number Systems
Number Systems and Arithmetic
Data Representation in Computers. Data Representation in Computers/Session 3 / 2 of 33 Number systems  The additive approach – Number earlier consisted.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Simple Data Type Representation and conversion of numbers
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number systems, Operations, and Codes
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
IT1004: Data Representation and Organization Negative number representation.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Lecture 2: 8/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Computer Math CPS120 Introduction to Computer Science Lecture 7.
CSE370, Lecture 2 Lecture 2: Number Systems  Logistics Webpage is up! HW1 is posted on the web in the calender --- due.
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.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Lecture 4: Digital Systems & Binary Numbers (4)
Cosc 2150: Computer Organization
Integer Real Numbers Character Boolean Memory Address CPU Data Types
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Logistics Always read the Calendar at
CSE 102 Introduction to Computer Engineering
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
ECE 331 – Digital System Design
Lecture 2: Number Systems
Presentation transcript:

1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded decimal (BCD)

2 Positional number notation Bases we will use  Binary: base 2  Octal: base 8  Decimal: base 10  Hexadecimal: base 16 Positional number system  = 1× × ×2 0 = 5 10  = 6× × ×8 –1 =  A1 16 = 10× ×16 0 =

3 Base conversion from binary Conversion to octal / hex  Binary:  Octal:10 | 011 | 110 | 001 =  Hex:100 | 1111 | 0001 = 4F1 16 Conversion to decimal  = 1× × ×2 0 = 5 10

4 Base conversion from decimal Why does this work?

5 Base conversion from decimal N = = Quotient = N / 2 = 56 / 2 = / 2 = remainder 0 Each successive division "liberates" a least significant bit

6 Arithmetic Decimal Binary – –

7 Negative numbers How do we write negative binary numbers?  Prefix numbers with minus symbol? 3 approaches:  Sign and magnitude  Ones-complement  Twos-complement All 3 approaches represent positive numbers in the same way

8 Sign and magnitude Most significant bit (MSB) is the sign bit  0 ≡ positive  1 ≡ negative Remaining bits are the number's magnitude – 0 – 1 – 2 – 3 – 4 – 5 – 6 – 7

9 Sign and magnitude Problem 1: Two representations of for zero  +0 = 0000 and also –0 = 1000 Problem 2: Arithmetic is cumbersome  4 – 3 != 4 + (-3)

10 Ones-complement Negative number: Bitwise complement of positive number  0111 ≡ 7 10  1000 ≡ – – 7 – 6 – 5 – 4 – 3 – 2 – 1 – 0

11 Ones-complement Solves the arithmetic problem end-around carry

12 Why ones-complement works The ones-complement of an 4-bit positive number y is – y  0111 ≡ 7 10  – = ≡ –7 10 What is ?  1 less than = 2 4 – 1  –y is represented by (2 4 – 1) – y

13 Why ones-complement works Adding representations of x and –y where x, y are positive numbers, we get x + ((2 4 – 1) – y) = (2 4 – 1) + (x – y)  If x < y, then x – y < 0. There will be no carry from (2 4 – 1) + (x – y). Just add representations to get correct negative number.  If x > y, then x – y > 0. There will be a carry. Performing end-around carry subtracts 2 4 and adds 1, subtracting (2 4 – 1) from (2 4 – 1) + (x – y)  If x = y, then answer should be 0, get (2 4 – 1) =

14 So what's wrong? Still have two representations for zero!  +0 = 0000 and also –0 = 1111

15 Twos-complement Negative number: Bitwise complement plus one  0111 ≡ 7 10  1001 ≡ –7 10 Benefits:  Simplifies arithmetic  Only one zero! – 8 – 7 – 6 – 5 – 4 – 3 – 2 – 1

16 Twos-complement

17 Why twos-complement works Recall: The ones-complement of a b- bit positive number y is (2 b – 1) – y Twos-complement adds one to the bitwise complement, thus, –y is 2 b – y  –y and 2 b – y are equal mod 2 b (have the same remainder when divided by 2 b )  Ignoring carries is equivalent to doing arithmetic mod 2 b

18 Why twos-complement works Adding representations of x and –y where x, y are positive numbers, we get x + (2 b – y) = 2 b + (x – y)  If there is a carry, that means that x  y and dropping the carry yields x – y  If there is no carry, then x < y, then we can think of it as 2 b – (y – x), which is the twos-complement representation of the negative number resulting from x – y.

19 Overflow Answers only correct mod 2 b  Summing two positive numbers can give a negative result  Summing two negative numbers can give a positive result – 8 – 7 – 6 – 5 – 4 – 3 – 2 – – 8 – 7 – 6 – 5 – 4 – 3 – 2 – ⇒ –6 –7 – 3 ⇒ +6

20 Miscellaneous Sign-extension  Write +6 and –6 as twos-complement 0110 and 1010  Sign-extend to 8-bit bytes and Can't infer a representation from a number  is 25 (unsigned)  is -9 (sign and magnitude)  is -6 (ones complement)  is -7 (twos complement)

21 BCD (Binary-Coded Decimal) Decimal Symbols BCD Code