D75P 34R - HNC Computer Architecture Week 4 Signed Integers © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen College unless otherwise.

Slides:



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

EET 1131 Unit 7 Arithmetic Operations and Circuits
Representing Numbers: Integers
EE1A2 Microprocessor Systems & Digital Logic Part I Digital Electronic System Design Dr. T. Collins.
DATA REPRESENTATION Y. Colette Lemard February
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
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 =
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.
Number Representation Rizwan Rehman, CCS, DU. Convert a number from decimal to binary notation and vice versa. Understand the different representations.
Review Binary Basic Conversion Binary Decimal
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.
Binary Arithmetic Math For Computers.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Binary Representation and Computer Arithmetic
Computer Systems 1 Fundamentals of Computing Negative Binary.
The Binary Number System
Data Representation Number Systems.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Computer Arithmetic Nizamettin AYDIN
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
IT253: Computer Organization
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Computer Math. The Decimal System How do we represent “One Hundred and Twenty Five”? How do we represent “One Hundred and Twenty Five”? Simple: 125 !!!
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.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Chapter 3 Number Representation. Convert a number from decimal to binary notation and vice versa. Understand the different representations of an integer.
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.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Number Representation
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Number Systems and Logic Prepared by Dr P Marais (Modified by D Burford)
Sep 29, 2004Subtraction (lvk)1 Negative Numbers and Subtraction The adders we designed can add only non-negative numbers – If we can represent negative.
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.
D75P 34R – HNC Computer Architecture Week 1 Introduction to Binary Storage © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen College unless.
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=
Representing Integer Data
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
© Prepared By: Razif Razali 1 CHAPTER TWO TCS1023 NUMBERING SYSTEM.
Integer Operations Computer Organization and Assembly Language: Module 5.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Number Representation 1 Lecture 2. Outcomes By the end of the session you should: – Understand what bits/bytes/words are. – Understanding conversion between.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Two’s Complement The language of machines, part II.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Cosc 2150: Computer Organization
Negative Numbers and Subtraction
Hexadecimal, Signed Numbers, and Arbitrariness
Computer Science 210 Computer Organization
Data Representation in Computer Systems
Computer Science 210 Computer Organization
Topic 3: Data Signed Binary.
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Fundamentals of Data Representation
OBJECTIVES After reading this chapter, the reader should be able to :
Two’s Complement & Binary Arithmetic
Presentation transcript:

D75P 34R - HNC Computer Architecture Week 4 Signed Integers © C Nyssen/Aberdeen College 2004 All images © C Nyssen /Aberdeen College unless otherwise stated Prepared 06/10/04

Up until now, we have been looking at how integer numbers are stored in binary. But all the numbers we have used so far have been unsigned - we have just been assuming, so far, that they are all positive numbers! ON -- 1or OFF- - 0 If computers can only store equivalents of 1 and 0, how does it cope with + and - signs?

To begin, let’s recap on how simple integers are stored. The above represents an 8-bit byte. If all the bits are set to 1, the integer has a decimal value of 255. If all the bits are set to 0, that value would be zero. So we can say that this byte can hold a range of values from There are 256 different possible values within that byte.

Let’s look at the same byte, but use it differently. The same 8-bit byte is used to hold the integer, but the leftmost bit - the most significant bit - has been isolated. In a moment, we will use that bit to determine whether the rest of the number is positive or negative. But as we are now only using 7 bits to store the actual number, the range will only be from 0 to 127.

Let’s look at the first bit in more detail... This particular bit is sometimes called a sign bit or sign flag. When it is set to 0, it means that the rest of the number is positive. When set to 1, it means that the rest of the number is negative. Be very, very careful not to confuse these values!

The above number represents …but this represents -127! The range of numbers we can now represent using the same 8 bits now runs from -127 to +127.

This method of representing negative numbers is called the sign-and-magnitude method. It can be represented by a number line like this…. It is very simple to implement from both a hardware and software viewpoint. It does, however, have one major flaw….

An 8-bit byte, with no sign flag, could hold number values of a total of 256 separate numbers. An 8-bit byte, with a sign flag - i.e. using 7 bits for the number and one for the sign - could hold number values of -127 to A total of 255 separate numbers! So where did the missing value go?!

What value does the above number represent? What would happen if we changed the sign to a 1? The reason we apparently “lost” a value is that 0 is being counted twice; we have, in effect, a “positive” and a “negative” zero!

Counting upwards would give us... … If we were to count the items, it would give us a “false” result - there are eight numbers shown above, but only seven different values! Whenever we count upwards or downwards and move from a positive to a negative value, the count will always be “one out”. For this reason, sign-and-magnitude is not used much in modern computer systems.

Another system, based on sign- and-magnitude, is used instead. It is called the two’s complement system, and works on the complement, or inverse, of the number. Let’s look at an example of a 10’s complement first…. If a car speedometer has three figures, the maximum number it can show will be 999. The complement of that is 1, because 1 added to 999 would reset the numbers to 000. Likewise, the complement of 762 would be 238. What would be the 10’s complement of 195?

Finding the 2’s complement of a binary number is actually very easy. Let’s say we wanted to show -17 in binary, using our original 8 bits. It’s very important to stick to the stated number of bits! Firstly, we make up the number 17. Ignore the sign flag for the moment.

Now comes the tricky part. As we have a negative number - i.e. the reverse of a positive one - we are going to reverse all the bits! So now it will look like this - We still haven’t taken the problem of our double-zero into account, though (remember we have crossed from the positive to the negative side of the numberline). To allow for this we add 1 to the rightmost - or least significant bit...

Finally, put the sign in to show that it’s negative. You can convert negative binary numbers back to decimal by doing the same thing in reverse... What’s this worth?

This immediately tells us we are dealing with a negative number. So we know we have to complement the rest of it... The reverse of is Add 1 to the last digit to get Convert back to decimal to get = 91 So the above value represents - 91!

What is the value of this number? This tells us we have a positive number. We can leave the rest alone.....and just do a simple conversion to decimal to get = 52. This number represents +52!

To see how the problem of the double-zero is resolved using two’s complement, take the smallest possible number in eight bits... …and the biggest one... What are the values of these two numbers?

You will now find that our range of numbers available over the eight bits runs from -128 to +127! We are back to our 256 possible combinations!

Easy binary subtraction with 2’s complement. Last week we were struggling with binary subtractions. It is a lot easier using 2’s complement and addition! Suppose we wanted to subtract 16 from 49… We could write and calculate this as Or we could write and calculate it as 49 + (-16), which would give us exactly the same result! All we are doing is working out the complement of 16, and adding it instead of subtracting.

Here’s our Here’s Reverse all the digits... And add 1 to the LSB to get

Add the +49 and the -16 to get this... Convert back to decimal to check…. …and the answer is indeed +33!

Summary.  Negative numbers can be shown using either sign-and- magnitude or two’s complement methods.  Both use the most significant bit to show the sign.  0 means positive, 1 means negative!  Sign and Magnitude can give inaccurate results, as the zero value may be counted in twice.  To find the two’s complement of a number, reverse all the digits then add one to the least significant bit.  Binary subtraction can be accomplished by adding the two’s complement of the original number to be subtracted.