Dr. ClincyLecture 2 Slide 1 CS 3501 - Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.

Slides:



Advertisements
Similar presentations
HEXADECIMAL NUMBERS Code
Advertisements

Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 2 Number Systems.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Level ISA3: Information Representation
Signed Numbers.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Digital Fundamentals Floyd Chapter 2 Tenth Edition
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
CSC 221 Computer Organization and Assembly Language
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Simple Data Type Representation and conversion of numbers
Data Representation – Binary 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.
Lecture Overview Introduction Positional Numbering System
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
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.
Data Representation in Computer Systems. 2 Objectives Understand the fundamentals of numerical data representation and manipulation in digital computers.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
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.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Operations on Bits Arithmetic Operations Logic Operations
Data Representation, Number Systems and Base Conversions
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
1 2.1 Introduction A bit is the most basic unit of information in a computer. –It is a state of “on” or “off” in a digital circuit. –Sometimes these states.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Chapter 1: Binary Systems
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
CSC 331: DIGITAL LOGIC DESIGN COURSE LECTURER: E. Y. BAAGYERE. CONTACT: LECTURE TIME: 15:40 – 17:45 hrs. VENUE: SP-LAB.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
Number Systems. Topics  The Decimal Number System  The Binary Number System  Converting from Binary to Decimal  Converting from Decimal to Binary.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
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.
Dr. Clincy Slide 1 CS Chapter 2 (Part 1 of 3) Dr. Clincy Professor of CS Ch 2 Appendix pages will not be on the exam – already covered this.
Cosc 2150: Computer Organization
Introduction To Number Systems
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Dr. Clincy Professor of CS
Data Representation in Computer Systems
COMPUTING FUNDAMENTALS
Chapter 3 Data Representation
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
University of Gujrat Department of Computer Science
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
Dr. Clincy Professor of CS
Data Representation in Computer Systems
Dr. Clincy Professor of CS
Data Representation in Computer Systems
Dr. Clincy Professor of CS
Chapter3 Fixed Point Representation
Dr. Clincy Professor of CS
Dr. Clincy Professor of CS
Presentation transcript:

Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered in the communications portion of this course)

2 Chapter 2 Objectives The architecture of a computer depends on how it represents numbers, characters and control info. Understand the fundamental concepts of number systems. Understand the fundamental concepts of floating-point representation. Gain familiarity with the most popular character codes. Understand the concepts of error detecting and correcting.

3 Introduction A bit is the most basic unit of information in a computer. –Sometimes these states are “high” or “low” voltage or “on” or “off..” A byte is a group of eight bits. –A byte is the smallest possible addressable unit of computer storage. A word is a contiguous group of bytes. –Words can be any number of bits or bytes. –Word sizes of 16, 32, or 64 bits are most common. –In a word-addressable system, a word is the smallest addressable unit of storage. A group of four bits is called a nibble. –Bytes, therefore, consist of two nibbles: a “high-order nibble,” and a “low-order” nibble.

Dr. ClincyLecture4 Positional Numbering Systems Review – Base 10 Numbers (Decimal) Base-10 The decimal number system is based on power of the base 10. For example, for the number 1259, the 9 is in the 10^0 column - 1s column the 5 is in the 10^1 column - 10s column the 2 is in the 10^2 column - 100s column the 1 is in the 10^3 column s column 1259 is 9 X 1 = X 10 = X 100 = X 1000 =

Dr. ClincyLecture5 Positional Numbering Systems Introducing Base 2 (Binary) and Base 16 (Hex) Number Systems Base-2 (Binary) The Binary number system uses the same mechanism and concept however, the base is 2 versus 10 The place values for binary are based on powers of the base 2: … 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^ Base-16 (Hex) The hexadecimal number system is based 16, and uses the same mechanisms and conversion routines we have already examined. The place values for hexadecimal are based on powers of the base 16 The digits for are the letters A - F (A is 10, …….., F is 15) …….. 16^3 16^2 16^1 16^

Dr. ClincyLecture6 5-bit Binary Number System 2 4, 2 3, 2 2, 2 1, , 8, 4, 2, 1

Dr. ClincyLecture7 Different Number Systems Base-10 (Decimal) – what are the characters ? Example = 659 Base-2 (Binary) – what are the characters ? Example = 1101 Base-16 (Hex) – what are the characters ? Example = AE Base-8 (Octal) – what are the characters ? Example = 73

8 Converting 190 to base 3... –3 5 = 243 is too large, so we try 3 4 = 81. And 2 times 81 doesn’t exceed 190 –The last power of 3, 3 0 = 1, is our last choice, and it gives us a difference of zero. –Our result, reading from top to bottom is: = Converting Between Bases – Subtraction Method

9 Converting 190 to base 3... –Continue in this way until the quotient is zero. –In the final calculation, we note that 3 divides 2 zero times with a remainder of 2. –Our result, reading from bottom to top is: = Converting Between Bases –Division Method

Dr. ClincyLecture10 Converting from Binary to Decimal So, the binary number can be converted to a decimal number 1 X 1 = 1 (right most bit or position) 1 X 2 = 2 0 X 4 = 0 0 X 8 = 0 1 X 16 = 16 1 X 32 = 32 0 X 64 = 0 1 X 128 = 128 (left most bit or position) in decimal

Dr. ClincyLecture11 Converting from Decimal to Binary To convert from decimal to some other number system requires a different method called the division/remainder method. The idea is to repeatedly divide the decimal number and resulting quotients by the number system’s base. The answer will be the remainders. Example: convert 155 to binary (Start from the top and work down) 155/2 Q = 77, R = 1 (Start) 77/2 Q = 38, R = 1 38/2 Q = 19, R = 0 19/2 Q = 9, R = 1 9/2 Q = 4, R = 1 4/2 Q = 2, R = 0 2/2 Q = 1, R = 0 1/2 Q = 0, R = 1 (Stop) Answer is Be careful to place the digits in the correct order.

12 Why Decimal, Binary and Hex ? Give subscripts for Decimal, Binary, Hex, Octal Converting Between Bases

13 Using groups of hextets, the binary number (= ) in hexadecimal is: Octal (base 8) values are derived from binary by using groups of three bits (8 = 2 3 ): Octal was very useful when computers used six-bit words. If the number of bits is not a multiple of 4, pad on the left with zeros. Converting Between Bases of Power 2

14 Fractional decimal values have nonzero digits to the right of the decimal point. Fractional values of other radix systems have nonzero digits to the right of the radix point. Numerals to the right of a radix point represent negative powers of the radix: = 4   = 1   2 -2 = ½ + ¼ = = 0.75 Converting Between Bases

15 The calculation to the right is an example of using the subtraction method to convert the decimal to binary. –Our result, reading from top to bottom is: = –Of course, this method works with any base, not just binary. Subtraction - Converting Between Bases

16 Converting to binary... –Multiplication Method: You are finished when the product is zero, or until you have reached the desired number of binary places. –Our result, reading from top to bottom is: = –This method also works with any base. Just use the target radix as the multiplier. Multiplication - Converting Between Bases

Dr. ClincyLecture17 Converting Number Systems

Dr. ClincyLecture 3 Slide 18 CS Chapter 2 (2 of 5) Dr. Clincy Professor of CS

Dr. ClincyLecture19 Addition Dr. Clincy19

Dr. ClincyLecture20 Addition & Subtraction Dr. Clincy20

What about multiplication in base 2 By hand - For unsigned case, very similar to base-10 multiplication Dr. ClincyLecture21Dr. Clincy21

Dr. ClincyLecture22 Division Dr. Clincy22

Dr. ClincyLecture23 Computers can not SUBTRACT Therefore, need approaches to represent “signed” numbers

Dr. ClincyLecture b 3 b 2 b 1 b 0 Sign and magnitude 1's complement2's complement BValues represented. Changing only b 3 makes +/-Complementing makes +/- Complementing plus 1 makes +/- More used and more efficient NOTE: S-M can be used to “represent” signed numbers however, 1’s and 2’s complement can also be used for subtraction

Dr. ClincyLecture25 5-bit Binary Number System with SIGN X 4, X 3, X 2, X 1, X 0 Sign

26 Example: –Using signed magnitude binary arithmetic, find the sum of 75 and 46. Once we have worked our way through all eight bits, we are done. In this example, we were careful to pick two values whose sum would fit into seven bits. If that is not the case, we have a problem. Sign Magnitude Approach Dr. ClincyLecture

27 Example: –Using signed magnitude binary arithmetic, find the sum of 107 and 46. We see that the carry from the seventh bit overflows and is discarded, giving us the erroneous result: = 25. Sign Magnitude Approach Dr. ClincyLecture

28 The signs in signed magnitude representation work just like the signs in pencil and paper arithmetic. –Example: Using signed magnitude binary arithmetic, find the sum of - 46 and Because the signs are the same, all we do is add the numbers and supply the negative sign when we are done. Sign Magnitude Approach Dr. ClincyLecture

29 Mixed sign addition (or subtraction) is done the same way; pencil and paper arithmetic –Example: Using signed magnitude binary arithmetic, find the sum of 46 and The sign of the result gets the sign of the number that is larger. –Note the “borrows” from the second and sixth bits. Sign Magnitude Approach Dr. ClincyLecture

30 Signed magnitude representation is easy for people to understand, but it requires complicated computer hardware. Another disadvantage of signed magnitude is that it allows two different representations for zero: positive zero and negative zero. For these reasons (among others) computers systems employ 1’s and 2’s complement approaches Sign Magnitude Approach Dr. ClincyLecture 9 and 10

31 For example, using 8-bit one’s complement representation: + 3 is : is: In one’s complement representation, as with signed magnitude, negative values are indicated by a 1 in the high order bit. Complement systems are useful because they eliminate the need for subtraction. One’s Complement Approach Dr. ClincyLecture 9 and 10

32 With one’s complement addition, the carry bit is “carried around” and added to the sum. –Example: Using one’s complement binary arithmetic, find the sum of 48 and -19 We note that 19 in binary is : , So -19 in one’s complement is: One’s Complement Approach Dr. ClincyLecture 9 and 10

Dr. ClincyLecture 9 and 1033 One’s Complement - Binary Addition 1010 (neg 5) (pos 2) 1100 (neg 3) 1101 (neg 2) (pos 7) (overflow – add the 1 back) 0101 (pos 5) Recall complement 0011

Dr. ClincyLecture 9 and ’s Complement

Dr. ClincyLecture 9 and ’s Complement

36 Although the “end carry around” adds some complexity, one’s complement is simpler to implement than signed magnitude. But it still has the disadvantage of having two different representations for zero: positive zero and negative zero. Two’s complement solves this problem. One’s Complement Approach Dr. ClincyLecture 9 and 10

37 To express a value in two’s complement representation: –If the number is positive, just convert it to binary and you’re done. –If the number is negative, find the one’s complement of the number and then add 1. Example: –In 8-bit binary, 3 is: –-3 using one’s complement representation is: –Adding 1 gives us -3 in two’s complement form: Two’s Complement Approach Dr. ClincyLecture 9 and 10

38 With two’s complement arithmetic, all we do is add our two binary numbers. Just discard any carries emitting from the high order bit. We note that 19 in binary is: , So -19 using one’s complement is: , So -19 using two’s complement is: –Example: Using two’s complement binary arithmetic, find the sum of 48 and Two’s Complement Approach Dr. ClincyLecture 9 and 10

39 Example: –Using two’s complement binary arithmetic, find the sum of 107 and 46. We see that the nonzero carry from the seventh bit overflows into the sign bit, giving us the erroneous result: = Sign-bit: Carry-in of 1 and Carry-out of 0 But overflow into the sign bit does not always mean that we have an error. Two’s Complement Approach Rule for detecting signed two’s complement overflow: When the “carry in” and the “carry out” of the sign bit differ, overflow has occurred. If the carry into the sign bit equals the carry out of the sign bit, no overflow has occurred. Dr. ClincyLecture 9 and 10

40 Example: –Using two’s complement binary arithmetic, find the sum of 23 and -9. –We see that there is carry into the sign bit and carry out. The final result is correct: 23 + (-9) = 14. –Sign-bit: Carry-in of 1 and Carry-out of 0 Rule for detecting signed two’s complement overflow: When the “carry in” and the “carry out” of the sign bit differ, overflow has occurred. If the carry into the sign bit equals the carry out of the sign bit, no overflow has occurred. Two’s Complement Approach Dr. ClincyLecture 9 and 10