signed numbers. until now we've been concentrating on unsigned numbers. in real life we also...
Post on 21-Dec-2015
216 views
TRANSCRIPT
![Page 1: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/1.jpg)
Signed Numbers
![Page 2: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/2.jpg)
Signed Numbers Until now we've been concentrating on unsigned
numbers. In real life we also need to be able represent signed numbers ( like: -12, -45, +78).
A signed number MUST have a sign (+/-). A method is needed to represent the sign as part of the binary representation.
Two signed number representation methods are:
Sign/magnitude representation
Twos-complement representation
![Page 3: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/3.jpg)
Sign/Magnitude Representation
In sign/magnitude (S/M) representation, the
leftmost bit of a binary code represents the sign of the value:
0 for positive, 1 for negative;
The remaining bits represent the numeric value.
![Page 4: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/4.jpg)
Sign/Magnitude Representation
To compute negative values using Sign/Magnitude (S/M) representation:
1) Begin with the binary representation of the positive value
2) Then flip the leftmost zero bit.
![Page 5: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/5.jpg)
Sign/Magnitude Representation
Ex 1. Find the S/M representation of -610
So: -610 = 100001102
(in 8-bit sign/magnitude form)
Step 2: If the number you want to represent is negative, flip leftmost bit
10000110
Step 1: Find binary representation using 8 bits
610 = 000001102
![Page 6: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/6.jpg)
Sign/Magnitude Representation
Ex 2. Find the S/M representation of 7010
Step 2: If the number you want to represent isnegative, flip left most bit
01000110 (positive -- no flipping)
Step 1: Find binary representation using 8 bits
7010 = 010001102
So: 7010 = 010001102
(in 8-bit sign/magnitude form)
![Page 7: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/7.jpg)
Sign/Magnitude Representation
Ex 3. Find the S/M representation of -3610
Step 2: If the number you want to represent isnegative, flip left most bit
10100100
Step 1: Find binary representation using 8 bits
-3610 = 001001002
So: -3610 = 101001002
(in 8-bit sign/magnitude form)
![Page 8: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/8.jpg)
Sign bit: 0 positive 1 negative
Sign bit: 0 positive 1 negative
31 remaining bits for magnitude (i.e. the value)
31 remaining bits for magnitude (i.e. the value)
32-bit example:
0 000 0000 0000 0000 0000 0000 0000 10011 000 0000 0000 0000 0000 0000 0000 1001
+9
-9
Sign/Magnitude Representation
![Page 9: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/9.jpg)
• Two different representations for 0!
0000
0111
0011
1011
11111110
1101
1100
1010
1001
10000110
0101
0100
0010
0001
+0
+1
+2
+3
+4
+5
+6
+7-0
-1
-2
-3
-4
-5
-6
-7
Inner numbers:Binary
representation
Seven Positive Numbers and “Positive” Zero
Seven Negative Numbers and
“Negative” Zero
• Two discontinuities
Problems with Sign/Magnitude
![Page 10: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/10.jpg)
Two’s Complement Representation
Another method used to represent negative numbers (used by most modern computers) is two’s complement.
The leftmost bit STILL serves as a sign bit: 0 for positive numbers, 1 for negative numbers.
![Page 11: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/11.jpg)
Two’s Complement Representation
To compute negative values using Two’s Complement representation:
1) Begin with the binary representation of the positive value
2) Complement (flip each bit -- if it is 0 make it 1 and visa versa) the entire positive number
3) Then add one.
![Page 12: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/12.jpg)
Two’s Complement Representation
Ex 1. Find the 8-bit two’s complement representation of –610
Step 1: Find binary representation of the positive value in 8 bits
610 = 000001102
![Page 13: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/13.jpg)
Two’s Complement Representation
Ex 1 continuedStep 2: Complement the entire
positive value
Positive Value: 00000110
Complemented: 11111001
![Page 14: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/14.jpg)
Two’s Complement Representation
So: -610 = 111110102
(in 8-bit 2's complement form)
Ex 1, Step 3: Add one to complemented value
(complemented) -> 11111001
(add one) -> + 1
11111010
![Page 15: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/15.jpg)
Two’s Complement Representation
Ex 2. Find the 8-bit two’s complement representation of 2010
Step 1: Find binary representation of the positive value in 8 bits
2010 = 000101002
20 is positive, so STOP after step 1!
So: 2010 = 000101002
(in 8-bit 2's complement form)
![Page 16: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/16.jpg)
Two’s Complement Representation
Ex 3. Find the 8-bit two’s complement representation of –8010
Step 1: Find binary representation of the positive value in 8 bits
8010 = 010100002
-80 is negative, so continue…
![Page 17: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/17.jpg)
Two’s Complement Representation
Ex 3 Step 2: Complement the entire positive
value
Positive Value: 01010000
Complemented: 10101111
![Page 18: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/18.jpg)
Two’s Complement Representation
So: -8010 = 101100002
(in 8-bit 2's complement form)
Ex 3, Step 3: Add one to complemented value
(complemented) -> 10101111
(add one) -> + 1
10110000
![Page 19: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/19.jpg)
Two’s Complement Representation Alternate method -- replaces previous
steps 2-3
Step 2: Scanning the positive binary representation from right to left,
find first one bit, from low-order (right) end
Step 3: Complement (flip) the remaining bits to the left.
00000110 (left complemented) --> 11111010
![Page 20: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/20.jpg)
Two’s Complement Representation
Ex 1: Find the Two’s Complement of -7610
Step 1: Find the 8-bit binary representation of the positive value.
7610 = 010011002
![Page 21: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/21.jpg)
Two’s Complement Representation
Step 2: Find first one bit, from low-order (right) end, and complement the pattern to the left.
01001100 (left complemented) -> 10110100
So: -7610 = 101101002
(in 8-bit 2's complement form)
![Page 22: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/22.jpg)
Two’s Complement Representation
Ex 2: Find the Two’s Complement of 7210
Step 1: Find the 8 bit binary representation of the positive value.
7210 = 010010002
Steps 2-3: 72 is positive, so STOP after step 1!
So: 7210 = 010010002
(in 8-bit 2's complement form)
![Page 23: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/23.jpg)
Two’s Complement Representation
Ex 3: Find the Two’s Complement of -2610
Step 1: Find the 8-bit binary representation of the positive value.
2610 = 000110102
![Page 24: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/24.jpg)
Two’s Complement Representation
Ex 3, Step 2: Find first one bit, from low-order (right) end, and complement the pattern to the left.
00011010(left complemented) -> 11100110
So: -2610 = 111001102
(in 8-bit 2's complement form)
![Page 25: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/25.jpg)
Sign bit: 0 --> positive 1 --> negative
Sign bit: 0 --> positive 1 --> negative
31 remaining bits for magnitude(i.e. value stored in two’s complement form)
31 remaining bits for magnitude(i.e. value stored in two’s complement form)
32-bit example:
0 000 0000 0000 0000 0000 0000 0000 10011 111 1111 1111 1111 1111 1111 1111 0111
+9
-9
Two’s Complement Representation
![Page 26: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/26.jpg)
Two’s Complement to Decimal
Ex 1: Find the decimal equivalent of the
8-bit 2’s complement value 111011002
Step 1: Determine if number is positive or negative:
Leftmost bit is 1, so number is negative.
![Page 27: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/27.jpg)
Two’s Complement to Decimal
Ex 1, Step 2: Find first one bit, from low-order (right) end, and complement the pattern to the left.
11101100
(left complemented) 00010100
![Page 28: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/28.jpg)
Two’s Complement to Decimal
Ex 1, Step 3: Determine the numeric value:
000101002 = 16 + 4 = 2010
So: 111011002 = -2010
(8-bit 2's complement form)
![Page 29: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/29.jpg)
Two’s Complement to Decimal
Ex 2: Find the decimal equivalent of the
8-bit 2’s complement value 010010002
Step 1: Determine if number is positive or negative:
Leftmost bit is 0, so number is positive.
Skip to step 3.
![Page 30: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/30.jpg)
Two’s Complement to Decimal
Ex2, Step 3: Determine the numeric value:
010010002 = 64 + 8 = 7210
So: 010010002 = 7210 (8-
bit 2's complement form)
![Page 31: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/31.jpg)
Two’s Complement to Decimal
Ex 3: Find the decimal equivalent of the
8-bit 2’s complement value 110010002
Step 1: Determine if number is positive or negative:
Leftmost bit is 1, so number is negative.
![Page 32: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/32.jpg)
Two’s Complement to Decimal
Ex 3, Step 2: Find first one bit, from low-order (right) end, and complement the pattern to the left.
11001000(left complemented) 00111000
![Page 33: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/33.jpg)
Two’s Complement to Decimal
Ex 3, Step 3: Determine the numeric value:
001110002 = 32 + 16 + 8 =
5610
So: 110010002 = -5610
(8-bit 2's complement form)
![Page 34: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/34.jpg)
• Only one discontinuity now
0000
0111
0011
1011
11111110
1101
1100
1010
1001
1000
0110
0101
0100
0010
0001
+0+1
+2
+3
+4
+5
+6
+7-8-7
-6
-5
-4
-3-2
-1
Inner numbers:Binary
representation
Eight Positive
Numbers
Re-order Negative numbers to eliminate one Discontinuity
Note: Negative Numbers still have 1 for the most significant bit (MSB)
• Only one zero• One extra negative number
S/M problems solved with 2s complement
![Page 35: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/35.jpg)
Two’s Complement Representation
Biggest reason two’s complement used in most systems today?
The binary codes can be added and subtracted as if they were unsigned binary numbers, without regard to the signs of the numbers they actually represent.
![Page 36: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/36.jpg)
Two’s Complement Representation
For example, to add +4 and -3, we simply add the corresponding binary codes, 0100 and 1101:
0100 (+4)+1101 (-3)
0001 (+1)
NOTE: A carry to the leftmost column has been ignored.
The result, 0001, is the code for +1, which IS the sum of +4 and -3.
![Page 37: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/37.jpg)
Twos Complement Representation
Likewise, to subtract +7 from +3: 0011 (+3)
- 0111 (+7) 1100 (-4) NOTE: A “phantom” 1 was borrowed from
beyond the leftmost position.
The result, 1100, is the code for -4, the result of subtracting +7 from +3.
![Page 38: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/38.jpg)
Two’s Complement Representation
Summary - Benefits of Twos Complements:
Addition and subtraction are simplified in the two’s-complement system,
-0 has been eliminated, replaced by one extra negative value, for which there is no corresponding positive number.
![Page 39: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/39.jpg)
Valid Ranges
For any integer data representation, there is a LIMIT to the size of number that can be stored.
The limit depends upon number of bits available for data storage.
![Page 40: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/40.jpg)
Unsigned Integer Ranges
Range = 0 to (2n – 1)
where n is the number of bits used to store the unsigned integer.
Numbers with values GREATER than (2n – 1) would require more bits. If you try to store too large a value without using more bits, OVERFLOW will occur.
![Page 41: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/41.jpg)
Unsigned Integer Ranges
Example: On a system that stores unsigned integers in 16-bit words:
Range = 0 to (216 – 1)
= 0 to 65535
Therefore, you cannot store numbers larger than 65535 in 16 bits.
![Page 42: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/42.jpg)
Signed S/M Integer Ranges
Range = -(2(n-1) – 1) to +(2(n-1) – 1)
where n is the number of bits used to store the sign/magnitude integer.
Numbers with values GREATER than +(2(n-1) – 1)
and values LESS than -(2(n-1) – 1) would require more bits. If you try to store too large/too small a value without using more bits, OVERFLOW will occur.
![Page 43: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/43.jpg)
S/M Integer Ranges
Example: On a system that stores unsigned integers in 16-bit words:
Range = -(215 – 1) to +(215 – 1)
= -32767 to +32767
Therefore, you cannot store numbers larger
than 32767 or smaller than -32767 in 16 bits.
![Page 44: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/44.jpg)
Two’s Complement Ranges
Range = -2(n-1) to +(2(n-1) – 1)
where n is the number of bits used to store the two-s complement signed integer.
Numbers with values GREATER than +(2(n-1) – 1)
and values LESS than -2(n-1) would require more bits. If you try to store too large/too small a value without using more bits, OVERFLOW will occur.
![Page 45: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/45.jpg)
Two’s Complement Ranges
Example: On a system that stores unsigned integers in 16-bit words:
Range = -215 to +(215 – 1)
= -32768 to +32767
Therefore, you cannot store numbers larger
than 32767 or smaller than -32768 in 16 bits.
![Page 46: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/46.jpg)
Using Ranges for Validity Checking
Once you know how small/large a value can be stored in n bits, you can use this knowledge to check whether you answers are valid, or cause overflow.
Overflow can only occur if you are adding two positive numbers or two negative numbers
![Page 47: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/47.jpg)
Using Ranges for Validity Checking
Ex 1:
Given the following 2’s complement equations in 5 bits, is the answer valid?
11111 (-1) Range =+11101 (-3) -16 to +15 11100 (-4) VALID
![Page 48: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/48.jpg)
Using Ranges for Validity Checking
Ex 2:
Given the following 2’s complement equations in 5 bits, is the answer valid?
10111 (-9) Range =+10101 (-11) -16 to +15 01100 (-20) INVALID
![Page 49: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/49.jpg)
Floating Point Numbers
![Page 50: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/50.jpg)
Floating Point Numbers
Now you've seen unsigned and signed integers. In real life we also need to be able represent numbers with fractional parts (like: -12.5 & 45.39).
Called Floating Point numbers.
You will learn the IEEE 32-bit floating point representation.
![Page 51: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/51.jpg)
Floating Point Numbers
In the decimal system, a decimal point (radix point) separates the whole numbers from the fractional part
Examples:
37.25 ( whole = 37, fraction = 25/100)
123.567
10.12345678
![Page 52: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/52.jpg)
Floating Point Numbers
For example, 37.25 can be analyzed as:
101 100 10-1 10-2
Tens Units Tenths Hundredths
3 7 2 5
37.25 = (3 x 10) + (7 x 1) + (2 x 1/10) + (5 x 1/100)
![Page 53: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/53.jpg)
Binary Equivalence
The binary equivalent of a floating point number can be determined by computing the binary representation for each part separately.
1) For the whole part:
Use subtraction or division method previously learned.
2) For the fractional part:
Use the subtraction or multiplication method (to be shown next)
![Page 54: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/54.jpg)
Fractional Part – Multiplication Method
In the binary representation of a floating point number the column values will be as follows:
… 25 24 23 22 21 20 . 2-1 2-2 2-3 2-4 …
… 32 16 8 4 2 1 . 1/2 1/4 1/8 1/16…
… 32 16 8 4 2 1 . .5 .25 .125 .0625…
![Page 55: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/55.jpg)
Fractional Part – Multiplication Method
Ex 1. Find the binary equivalent of 0.25 Step 1: Multiply the fraction by 2 until the fractional part
becomes 0 .25 x 2 0.5
x 2 1.0
Step 2: Collect the whole parts in forward order. Put
them after the radix point
. .5 .25 .125 .0625 . 0 1
![Page 56: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/56.jpg)
Fractional Part – Multiplication Method
Ex 2. Find the binary equivalent of 0.625 Step 1: Multiply the fraction by 2 until the fractional part
becomes 0 .625 x 2 1.25
x 2 0.50
x 21.0
Step 2: Collect the whole parts in forward order. Put them after the radix point
. .5 .25 .125 .0625 . 1 0 1
![Page 57: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/57.jpg)
Fractional Part – Subtraction Method
Start with the column values again, as follows:
… 20 . 2-1 2-2 2-3 2-4 2-5 2-6…
… 1 . 1/2 1/4 1/8 1/16 1/32 1/64…
… 1 . .5 .25 .125 .0625 .03125 .015625…
![Page 58: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/58.jpg)
Fractional Part – Subtraction Method
Starting with 0.5, subtract the column values from left to right. Insert a 0 in the column if the value cannot be subtracted or 1 if it can be. Continue until the fraction becomes .0
Ex 1.
.25 .5 .25 .125 .0625 - .25 .0 1 .0
![Page 59: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/59.jpg)
Binary Equivalent of FP number
Ex 2. Convert 37.25, using subtraction method.
64 32 16 8 4 2 1 . .5 .25 .125 .0625
26 25 24 23 22 21 20 . 2-1 2-2 2-3 2-4
1 0 0 1 0 1 37 - 32
5 - 4
1-1
0
. 0 1 .25
- .25 .0
37.2510 = 100101.012
![Page 60: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/60.jpg)
Binary Equivalent of FP number
Ex 3. Convert 18.625, using subtraction method. 64 32 16 8 4 2 1 . .5 .25 .125 .0625 26 25 24 23 22 21 20 . 2-1 2-2 2-3 2-4
1 0 0 1 0 1 0 1
18 .625 - 16 - .5 2 .125
- 2 - .125 0 0
18.62510 = 10010.1012
![Page 61: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/61.jpg)
Problem storing binary form
We have no way to store the radix point!
Standards committee came up with a way to store floating point numbers (that have a decimal point)
![Page 62: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/62.jpg)
IEEE Floating Point Representation
Floating point numbers can be stored into 32-bits, by dividing the bits into three parts:
the sign, the exponent, and the mantissa.
1 2 9 10 32
![Page 63: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/63.jpg)
IEEE Floating Point Representation
The first (leftmost) field of our floating point representation will STILL be the sign bit:
0 for a positive number, 1 for a negative number.
![Page 64: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/64.jpg)
Storing the Binary Form
How do we store a radix point?
- All we have are zeros and ones…
Make sure that the radix point is ALWAYS in the same position within the number.
Use the IEEE 32-bit standard
the leftmost digit must be a 1
![Page 65: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/65.jpg)
Solution is NormalizationEvery binary number, except the one corresponding to the number zero, can be normalized by choosing the exponent so that the radix point falls to the right of the leftmost 1 bit.
37.2510 = 100101.012 = 1.0010101 x 25
7.62510 = 111.1012 = 1.11101 x 22
0.312510 = 0.01012 = 1.01 x 2-2
![Page 66: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/66.jpg)
IEEE Floating Point Representation
The second field of the floating point number will be the exponent.
The exponent is stored as an unsigned 8-bit number, RELATIVE to a bias of 127. Exponent 5 is stored as (127 + 5) or 132
132 = 10000100 Exponent -5 is stored as (127 + (-5)) or 122
122 = 01111010
![Page 67: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/67.jpg)
Try It Yourself
How would the following exponents be stored (8-bits, 127-biased):
2-10
28
(Answers on next slide)
![Page 68: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/68.jpg)
Answers
2-10
exponent -10 8-bit
bias +127 value
117 01110101
28 exponent 8 8-bit
bias +127 value
135 10000111
![Page 69: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/69.jpg)
IEEE Floating Point Representation
The mantissa is the set of 0’s and 1’s to the right of the radix point of the normalized (when the digit to the left of the radix point is 1) binary number.
Ex: 1.00101 X 23
(The mantissa is 00101)
The mantissa is stored in a 23 bit field, so we add zeros to the right side and store:
00101000000000000000000
![Page 70: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/70.jpg)
Decimal Floating Point toIEEE standard Conversion
Ex 1: Find the IEEE FP representation of 40.15625
Step 1.
Compute the binary equivalent of the whole part and the fractional part. (i.e. convert 40 and .15625 to their binary equivalents)
![Page 71: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/71.jpg)
Decimal Floating Point toIEEE standard Conversion
40 .15625- 32 Result: -.12500 Result: 8 101000 .03125 .00101- 8 -.03125 0 .0
So: 40.1562510 = 101000.001012
![Page 72: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/72.jpg)
Decimal Floating Point toIEEE standard Conversion
Step 2. Normalize the number by moving the decimal point to the right of the leftmost one.
101000.00101 = 1.0100000101 x 25
![Page 73: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/73.jpg)
Decimal Floating Point toIEEE standard Conversion
Step 3. Convert the exponent to a biased exponent
127 + 5 = 132
And convert biased exponent to 8-bit unsigned binary:
13210 = 100001002
![Page 74: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/74.jpg)
Decimal Floating Point toIEEE standard Conversion
Step 4. Store the results from steps 1-3:
Sign Exponent Mantissa
(from step 3) (from step 2)
0 10000100 01000001010000000000000
![Page 75: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/75.jpg)
Decimal Floating Point toIEEE standard ConversionEx 2: Find the IEEE FP representation of –24.75 Step 1. Compute the binary equivalent of the whole
part and the fractional part.
24 .75- 16 Result: - .50 Result: 8 11000 .25 .11- 8 - .25 0 .0
So: -24.7510 = -11000.112
![Page 76: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/76.jpg)
Decimal Floating Point toIEEE standard Conversion
Step 2.
Normalize the number by moving the decimal point to the right of the leftmost one.
-11000.11 = -1.100011 x 24
![Page 77: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/77.jpg)
Decimal Floating Point toIEEE standard Conversion.
Step 3. Convert the exponent to a biased exponent
127 + 4 = 131
==> 13110 = 100000112
Step 4. Store the results from steps 1-3
Sign Exponent mantissa1 10000011 1000110..0
![Page 78: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/78.jpg)
IEEE standard to Decimal Floating Point Conversion.
Do the steps in reverse order
In reversing the normalization step move the radix point the number of digits equal to the exponent: If exponent is positive, move to the right If exponent is negative, move to the left
![Page 79: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/79.jpg)
IEEE standard to Decimal Floating Point Conversion.
Ex 1: Convert the following 32-bit binary number to its decimal floating point equivalent:
Sign Exponent Mantissa 1 01111101 010..0
![Page 80: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/80.jpg)
IEEE standard to Decimal Floating Point Conversion..
Step 1: Extract the biased exponent and unbias it
Biased exponent = 011111012 = 12510
Unbiased Exponent: 125 – 127 = -2
![Page 81: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/81.jpg)
Step 2: Write Normalized number in the form:
1 . ____________ x 2 ----
For our number:-1. 01 x 2 –2
IEEE standard to Decimal Floating Point Conversion..
Mantissa
Exponent
![Page 82: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/82.jpg)
IEEE standard to Decimal Floating Point Conversion.
Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part):
-0.01012 (negative exponent – move left)
Step 4: Convert binary number to the FP equivalent
(i.e. Add all column values with 1s in them)
-0.01012 = - ( 0.25 + 0.0625)
= -0.312510
![Page 83: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/83.jpg)
IEEE standard to Decimal Floating Point Conversion.
Ex 2: Convert the following 32 bit binary number to its decimal floating point equivalent:
Sign Exponent Mantissa
0 10000011 10011000..0
![Page 84: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/84.jpg)
IEEE standard to Decimal Floating Point Conversion..
Step 1: Extract the biased exponent and unbias it
Biased exponent = 10000112 = 13110
Unbiased Exponent: 131 – 127 = 4
![Page 85: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/85.jpg)
IEEE standard to Decimal Floating Point Conversion..
Step 2: Write Normalized number in the form:
1 . ____________ x 2 ----
For our number:
1.10011 x 2 4
Mantissa
Exponent
![Page 86: Signed Numbers. Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers ( like: -12, -45,](https://reader038.vdocument.in/reader038/viewer/2022103022/56649d545503460f94a30fa6/html5/thumbnails/86.jpg)
IEEE standard to Decimal Floating Point Conversion.
Step 4: Convert binary number to the FP equivalent (i.e. Add all column values with 1s in them)
11001.1 = 16 + 8 + 1 +.5
= 25.510
Step 3: Denormalize the binary number from step 2 (i.e. move the decimal and get rid of (x 2n) part:
11001.12 (positive exponent – move right)