# COMP2130 Winter 2015 Storing signed numbers in memory.

## Presentation on theme: "COMP2130 Winter 2015 Storing signed numbers in memory."— Presentation transcript:

COMP2130 Winter 2015 Storing signed numbers in memory

Single Precision Floats IEEE 754 32 Bit

Floating Point (32 bit) Mantissa (0-22) Exponent (23-30) Signed bit (31) 0 = positive 1 = negative

Floating Point (32 bit) 0  Convert 173.7  Positive so sign bit 31 = 0

Floating Point (32 bit) Convert 173.7 Positive so bit 31 = 0 Need to convert to 1.xxxxxx number 0

Floating Point (32 bit) Convert to 1.xxxxxx number 173.7 / 2 = 86.85 2 1 86.85 / 2 = 43.425 2 2 43.425 / 2 = 21.7125 2 3 21.7125 / 2 = 10.85625 2 4 10.85625 / 2 = 5.428125 2 5 5.428125 / 2 = 2.7140625 2 6 2.7140625 / 2 = 1.35703125 2 7 >= 1.0 use Log 2 (173.7), 173.7/2 x 0

Floating Point (32 bit) 173.7 = 1.35703125x2 7 Time to fill in the exponent Has a bias of 127 127 + 7 = 134 134 in unsigned 8 bit binary is 10000110 0

Floating Point (32 bit) 173.7 = 1.35703125x2 7 Time to fill in the exponent Has a bias of 127 127 + 7 = 134 134 in unsigned 8 bit binary is 10000110 010 000110

Floating Point (32 bit) 1.35703125x2 7 Now we will need to deal with the orange part of the number which will be placed into the mantissa 010 000110

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 0

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 01

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 010

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0110

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 01110

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 011100

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0111100

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0.71.41 01111100

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0.71.41 0.40.80 011111000

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0.71.41 0.40.80 1.61 0111111000

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0.71.41 0.40.80 1.61 0.61.21 01111111000

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0.71.41 0.40.80 1.61 0.61.21 0.20.40 011111110000

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0.71.41 0.40.80 1.61 0.61.21 0.20.40 011111110000

Floating Point (32 bit) 010 000110 Numberx2Whole 0.357031250.71406250 1.4281251 0.4281250.856250 1.71251 0.71251.4251 0.4250.850 1.71 0.71.41 0.40.80 1.61 0.61.21 0.20.40 01111111010010110000110

Floating Point (32 bit) 173.7 = 0 10000110 01011011011001100110011

Floating Point (32 bit) What if 173.7 was -173.7?

Floating Point (32 bit) What if 173.7 was -173.7? 173.7 = 0 10000110 01011011011001100110011

Floating Point (32 bit) What if 173.7 was -173.7? 173.7 = 0 10000110 01011011011001100110011 -173.7 = 1 10000110 01011011011001100110011