3. Representing Integer Data

Slides:



Advertisements
Similar presentations
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
Advertisements

CS 151 Digital Systems Design Lecture 3 More Number Systems.
Signed Numbers Up till now we've been concentrating on unsigned numbers. In real life we have to represent signed numbers ( like: -12, -45, 78). The difference.
Signed Numbers.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
1 CSE1301 Computer Programming Lecture 28 Number Representation (Integer)
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
Mathematics with Binary. Question  Below is a binary string  Which is the least significant bit (LSB)?  Which is the most significant bit (MSB)? 0.
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.
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.
School of Computer Science G51CSA 1 Computer Arithmetic.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
Computer Systems 1 Fundamentals of Computing Negative Binary.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Number Representations and Computer Arithmetic. CS 21a 9/23/02 Odds and Ends Slide 2 © Luis F. G. Sarmenta and John Paul Vergara, Ateneo de Manila University.
Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF.
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,
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
CPS120: Introduction to Computer Science Computer Math: Signed Numbers.
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.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Chapter 2: The Logic of Compound Statements 2.5 Application: Number Systems and Circuits for Addition 1 Counting in binary is just like counting in decimal.
Positional Number Systems
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.
ITEC 1011 Introduction to Information Technologies 4. Floating Point Numbers Chapt. 5.
INEL 4215: Computer Architecture and Organization Number Systems Signed numbers.
By Jariya Phongsai A two's-complement system is a system in which negative numbers are represented by the two's complement of the absolute value; this.
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.6 Instructor: Lin Chen Sept 2013.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Representing Integer Data
Floating Point Numbers
IT1004: Data Representation and Organization Negative number representation.
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.
ECE 3110: Introduction to Digital Systems Number Systems: signed numbers.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Computer Organization 1 Data Representation Negative Integers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
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.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Arithmetic James A. Rome Tennessee Governor's Academy August 2010.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Negative Binary Numbers
Negative Binary Numbers
Unit 18: Computational Thinking
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
Presentation transcript:

3. Representing Integer Data Chapt. 4

Ranges for Data Formats No. of bits Binary BCD ASCII 1 0 – 1 2 0 – 3 3 0 – 7 4 0 – 15 0 – 9 5 0 – 31 6 0 – 63 7 0 – 127 8 0 – 255 0 – 99 9 0 – 511 16 0 - 65,535 0 – 9999 24 0 – 16,777,215 0 – 999999 0 – 999 Etc.

In General (binary) No. of bits Binary Min Max n 2n - 1

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., -510 = ?2 Two common schemes: sign-magnitude and twos 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: 0 0 0 1 0 1 +ve 5 -5: 1 0 0 1 0 1 -ve 5

Ranges (revisited) No. of bits Binary Unsigned Sign-magnitude Min Max 1 2 3 -1 7 -3 4 15 -7 5 31 -15 6 63 -31 Etc.

In General (revisited) No. of bits Binary Unsigned Sign-magnitude Min Max n 2n - 1 -(2n-1 - 1) 2n-1 - 1

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

Complementary Representations 9’s complement 10’s complement 1’s complement Read sections 4.4 and 4.5 (pp. 102-113)

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

Exercises – Complementary Notations Answer What is the 3-digit 10’s complement of 247? Answer: 753 What is the 3-digit 10’s complement of 17? Answer: 983 777 is a 10’s complement representation of what decimal value? Answer: 223 See p. 110-111

Twos 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… Decide upon the number of bits (n) Find the binary representation of the +ve value in n-bits Flip all the bits (change 1’s to 0’s and vice versa) Add 1

Twos Complement Example Represent -5 in binary using 2’s complement notation Decide on the number of bits Find the binary representation of the +ve value in 6 bits Flip all the bits Add 1 6 (for example) 000101 +5 111010 111010 + 1 111011 -5

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: 0 0 0 1 0 1 +ve 5 -5: 1 1 1 0 1 1 -ve ? (previous slide)

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

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

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

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

Range for 2’s Complement For example, 6-bit 2’s complement notation 100000 100001 111111 000000 000001 011111 -32 -31 ... -1 0 1 ... 31 Negative, sign bit = 1 Zero or positive, sign bit = 0

Ranges (revisited) No. of bits Binary Unsigned Sign-magnitude 2’s complement Min Max 1 2 3 -1 -2 7 -3 -4 4 15 -7 -8 5 31 -15 -16 6 63 -31 -32 Etc.

In General (revisited) No. of bits Binary Unsigned Sign-magnitude 2’s complement Min Max n 2n - 1 -(2n-1 - 1) 2n-1-1 -2n-1 2n-1 - 1

2’s Complement Addition Easy No special rules Just add

What is -5 plus +5? Zero, of course, but let’s see -5: 10000101 +5: +00000101 10001010 Sign-magnitude -5: 11111011 +5: +00000101 00000000 Twos-complement 1

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) = 7 001010 +111101 000111 +3: 000011 1s C: 111100 +1: 1 -3: 111101

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

Thank You