sd & d negative numbers
TRANSCRIPT
![Page 1: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/1.jpg)
![Page 2: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/2.jpg)
Real Numbers & IntegersAll numbers belong to the set or group called real numbers.
Inside the set of real numbers is a set of all positive and negative whole numbers.
This set is called integers.
Real numbers
-4.6
2.46
13.7
Integers0
-7
5221
-31100.052
-52.4140.0014
![Page 3: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/3.jpg)
Signed Bit RepresentationThe simplest way of representing a negative number in binary is to use the first bit of the number to represent whether the number is positive or negative:
011 = 3111 = -3
This is known as signed bit representation.
![Page 4: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/4.jpg)
Signed Bit RepresentationThe simplest way of representing a negative number in binary is to use the first bit of the number to represent whether the number is positive or negative:
011 = 3111 = -3
This is known as signed bit representation.
The problem with signed bit representation is that there are 2 values for zero:
000 = 0100 = -0
![Page 5: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/5.jpg)
Two’s Complement RepresentationA better way of representing negative numbers in binary is by using Two’s Complement.
Two’s Complement is designed so that:
Binary Decimal11111101 -311111110 -211111111 -100000000 000000001 100000010 200000011 3
1. the set of integers show symmetry about zero
![Page 6: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/6.jpg)
Two’s Complement RepresentationTwo’s complement is designed so that:
00000010+ 1
00000011
2. adding 1 to any number produces the next number (ignoring carry bits)
![Page 7: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/7.jpg)
Two’s Complement RepresentationTo find the Two’s Complement of a number (its opposite sign):
1. Change all the 1’s to 0 and 0’s to 1.
2. Add 1.
![Page 8: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/8.jpg)
Two’s Complement RepresentationFor example, how would -5 be represented using Two’s Complement?
5 = 000000101
1. Change all the 1’s to 0 and 0’s to 1.
11111010
![Page 9: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/9.jpg)
Two’s Complement RepresentationFor example, how would -5 be represented using Two’s Complement?
5 = 000000101
1. Change all the 1’s to 0 and 0’s to 1.
11111010
2. Add 1.
11111010 +111111011
So -5 as Two’s Complement = 11111011
![Page 10: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/10.jpg)
Two’s Complement RepresentationExample 2 - find the Two’s Complement of 88
88 = 01011000
1. Change all the 1’s to 0 and 0’s to 1.
10100111
![Page 11: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/11.jpg)
Two’s Complement RepresentationExample 2 - find the Two’s Complement of 88
88 = 01011000
1. Change all the 1’s to 0 and 0’s to 1.
10100111
2. Add 1.
10100111 +110101000
So -88 as Two’s Complement = 10101000
![Page 12: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/12.jpg)
RangeThe number of integers which could be stored in one byte (8 bits) is
28 = 256
![Page 13: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/13.jpg)
RangeThe number of integers which could be stored in one byte (8 bits) is
28 = 256 The range of integers which could be stored in one byte (8 bits) using Two’s Complement is
-128 to +127
Why does there seem to be one less positive number?
There are 255 numbers plus the value 0. So there are 256 numbers in all.
![Page 14: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/14.jpg)
RangeWhat range of numbers could be stored in two bytes using twos complement?
216 = 65536
![Page 15: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/15.jpg)
RangeWhat range of numbers could be stored in two bytes using twos complement?
216 = 65536The range of integers which could be stored in two bytes (16 bits) is
-32768 to +32767
![Page 16: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/16.jpg)
RangeWhat range of numbers could be stored in two bytes using twos complement?
216 = 65536The range of integers which could be stored in two bytes (16 bits) is
-32768 to +32767
This method of representing large numbers is unsuitable because of the increased memory needed to store the large number of bits needed.
A solution to this is to use Floating Point Representation.
![Page 17: SD & D Negative Numbers](https://reader035.vdocuments.us/reader035/viewer/2022062503/58745ce11a28abd53e8ba481/html5/thumbnails/17.jpg)
CreditsHigher Computing – Data Representation – Representation of Negative Numbers
Produced by P. Greene and adapted by R. G. Simpson for the City of Edinburgh Council 2004
Adapted by M. Cunningham 2010