Representing Integer Data Book : Chapter 4 1 3419 ( Subject has no point !! ) 7652993002 477 666 11011011011011 A99ACF.

Slides:



Advertisements
Similar presentations
COE 202: Digital Logic Design Signed Numbers
Advertisements

CHAPTER 4: Representing Integer Data The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander.
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
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.
CSE20 Lecture 3 Number Systems: Negative Numbers 1.Sign and Magnitude Representation 2.1’s Complement Representation 3.2’s Complement Representation 1.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are 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.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Number System and Codes
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.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
3. Representing Integer Data
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
CHAPTER 5: Representing Numerical Data
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
Dale & Lewis Chapter 3 Data Representation. Data and computers Everything inside a computer is stored as patterns of 0s and 1s Numbers, text, audio, video,
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
9.4 FLOATING-POINT REPRESENTATION
Calculating Two’s Complement. The two's complement of a binary number is defined as the value obtained by subtracting the number from a large power of.
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.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Number Representation
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
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.
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
CS1Q Computer Systems Lecture 2 Simon Gay. Lecture 2CS1Q Computer Systems - Simon Gay2 Binary Numbers We’ll look at some details of the representation.
Representing Integer Data
IT1004: Data Representation and Organization Negative number representation.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
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.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
CHAPTER 5: Representing Numerical Data
CHAPTER 4: Representing Integer Data
Unit 18: Computational Thinking
Presentation transcript:

Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF

Basic Definition An integer is a number which has no fractional part. Examples:

Ranges for Data Formats Etc. 0 – 9990 – – 16,777, – 990 – , – – 90 – 990 – – – – – 90 – – 73 0 – 32 0 – 11 ASCIIBCDBinaryNo. of bits

In General (binary) No. of bits Binary MinMax n 02 n - 1 Remember !!

Signed Integers Previous examples were for “unsigned integers” (positive values only!) Must also have a mechanism to represent “signed integers” (positive and negative values!) E.g., = ? 2 Two common schemes: 1) sign-magnitude 2) two’s complement

Sign-Magnitude Extra bit on left to represent sign 0 = positive value 1 = negative value E.g., 6-bit sign-magnitude representation of +5 and –5: +5: ve 5 -5: ve 5

Ranges (revisited) No. of bits Binary UnsignedSign-magnitude MinMaxMinMax Etc.

In General (revisited) No. of bits Binary UnsignedSign-magnitude MinMaxMinMax n02 n - 1-(2 n-1 - 1)2 n-1 - 1

Difficulties with Sign-Magnitude Two representations of zero Using 6-bit sign-magnitude… 0: : Arithmetic is awkward! pp

Complementary Representations 9’s complement 10’s complement 1’s complement

Figure 4.5 Range shifting decimal integers Range shifting decimal integers – 9’s complement

9’s Decimal Complement Taking the complement: subtracting a value from a standard basis value Decimal (base 10) system diminished radix complement Radix minus 1 = 10 – 1 9 as the basis 3-digit example: base value = 999 Range of possible values 0 to 999 arbitrarily split at 500 NumbersNegativePositive Representation methodComplementNumber itself Range of decimal numbers Calculation999 minus numbernone Representation example – Increasing value+ 999 – 499

Find the 9’s Complement representation for the 3 digit number

Find the 9’s Complement representation for the 4 digit number

Find the 9’s Complement representation for the 4 digit number

Figure 4.6 Addition as a counting process Addition as a counting process

Using 9’s Complement. If we are using 4 bits, the number 5450 represents ? 9999 –

Figure 4.7 Addition with wraparound Addition with wraparound (-300) = -100

Addition with End-around Carry Count to the right crosses the modulus End-around carry Add 2 numbers in 9’s complementary arithmetic If the result has more digits than specified, add carry to the result +300 Representation Number represented (1099)

Figure 4.10 One’s complement representation One’s complement representation + -

Finding one’s complement for a negative Number Invert the bits ! For example one’s complement of -58 using 8 bits = = -58

Addition Add 2 positive 8-bit numbers Add 2 8-bit numbers with different signs Take the 1’s complement of 58 (i.e., invert) = =– =– = = = =13 Invert to get magnitude

Addition with Carry 8-bit number (2 10 ) Add 9 bits End-around carry = =–2– =104

Subtraction 8-bit number Invert (90 10 ) Add 9 bits End-around carry = = =106 – = =16

Overflow 8-bit number 256 different numbers Positive numbers: 0 to 127 Add Test for overflow 2 positive inputs produced negative result overflow! Wrong answer! Programmers beware: some high-level languages, e.g., some versions of BASIC, do not check for overflow adequately = = Invert to get magnitude

Figure 4.11 Ten’s complement scale Ten’s complement scale

What is the 3-digit 10’s complement of 247?

Exercises – Complementary Notations What is the 3-digit 10’s complement of 17? Answer: 777 is a 10’s complement representation of what decimal value? Answer: Skip answer Answer

What is the 3-digit 10’s complement of 17? Answer: is a 10’s complement representation of what decimal value? Answer: Exercises – Complementary Notations Answer

Two’s Complement Most common scheme of representing negative numbers in computers Affords natural arithmetic (no special rules!) To represent a negative number in 2’s complement notation… 1.Decide upon the number of bits (n) 2.Find the binary representation of the positive value in n-bits 3.Flip all the bits (change 1’s to 0’s and vice versa) 4.Add 1 Learn! kc

Figure 4.12 Two’s complement representation Two’s complement representation

Two’s Complement Example Represent –5 in binary using 2’s complement notation 1.Decide on the number of bits 2.Find the binary representation of the +ve value in 6 bits 3.Flip all the bits 4.Add 1 6 (for example)

Sign Bit In 2’s complement notation, the MSB is the sign bit (as with sign-magnitude notation) 0 = positive value 1 = negative value -5: ve +5: ve 5 ? (previous slide)

“Complementary” Notation Conversions between positive and negative numbers are easy For binary (base 2)… +ve -ve 2’s C

Example +5 2’s C -5 2’s C

Exercise – 2’s C conversions What is -20 expressed as an 8-bit binary number in 2’s complement notation? Answer: is a 7-bit binary number in 2’s complement notation. What is the decimal value? Answer:

What is -20 expressed as an 8-bit binary number in 2’s complement notation? Answer: is a 7-bit binary number in 2’s complement notation. What is the decimal value? Answer: -29 Exercise – 2’s C conversions Answer

Detail for -20 -> : PositiveValue = “Flip”: Add 1: kc (One’s complement)

Detail for > ’s Complement: “Flip”: Add One: Converts to: = - 29 kc (One’s complement)

Range for 2’s Complement For example, 6-bit 2’s complement notation Negative, sign bit = 1Zero or positive, sign bit = 0

Ranges (revisited) No. of bits Binary UnsignedSign-magnitude2’s complement MinMaxMinMaxMinMax Etc.

In General (revisited) No. of bits Binary UnsignedSign-magnitude2’s complement MinMaxMinMaxMinMax n02 n - 1-(2 n-1 - 1)2 n n-1 2 n Hint! Learn this table!

2’s Complement Addition Easy No special rules Just add

What is -5 plus +5? Zero, of course, but let’s see -5: : Sign-magnitude -5: : Twos-complement

2’s Complement Subtraction Easy No special rules Just subtract, well … actually … just add! A – B = A + (-B) add 2’s complement of B

What is 10 subtract 3? 7, of course, but… Let’s do it (we’ll use 6-bit values) 10 – 3 = 10 + (-3) = : s C: : 1 -3:

What is 10 subtract -3? 13, of course, but… Let’s do it (we’ll use 6-bit values) 10 – (-3) = 10 + (-(-3)) = : s C: : 1 +3: (-(-3)) = 3

Overflow the result of the calculation does not fit the available number of bits for the result Ex: 1 sign bit, 2 bits for the number Detection: sign of the result is different then the signs of the operands

Overflow 8-bit number 256 different numbers Positive numbers: 0 to 127 Add Test for overflow 2 positive inputs produced negative result overflow! Wrong answer! Programmers beware: some high-level languages, e.g., some versions of BASIC, do not check for overflow adequately = = Invert to get magnitude

Carry the result of an addition (or subtraction) exceeds the allocated bits, independently of the sign Ex: 1 sign bit, 2 bits for the number (carry, not overflow)