Module3 Unit2 LectureSlides
Module3 Unit2 LectureSlides
Representation of Data
Module 3 Unit2
Fraction and
Character Data Representation
Dr. S. A. Bashir
Department of Computer Science
FUT Minna
CPT11 1
Outline
• Representation of Fractions
CPT11 1
Fractions to binary
-1.25 to binart
0.625 to binary Convert 1.25 to binary
0.625x2=1.25 -> 1 1= 01
0.25 x2 =0.5 -> 0 0.25 to binary
0.5x2 =1 .0 -> 1 0.25x2=0.5 -> 0
0.625 to binary = .101 0.5 x2 =1.0 -> 1
0.25 = .01
-1.25 to binary = - 01.01
CPT11 1
Very Large and Very Small: Floating-
Point
• Large values: 6.023 x 1023 -- requires 79 bits
• Small values: 6.626 x 10-34 -- requires >110 bits
• Use equivalent of “scientific notation”: F x 2E
• Need to represent F (fraction), E (exponent), and sign.
• IEEE 754 Floating-Point Standard (32-bits):
1b 8b 23b
S Exponent Fraction
CPT11 1
Decimal to 32 bit floating point
1. Change absolute value of the decimal number to
binary
18.5 to IEEE 754 32 BITS FLOATING POINT STANDARD
2. Write the binary in normalized form (i.e scientific
Step 1: 18.5 TO BINARY = 10010. 1
notation ) by moving radix point so there is only a
single 1 bit to the left of the radix point. Step 2: 1.00101 x 24
Step3 : Fraction to be stored in bits 0 to 22 (23bits)
• Every position moved to the left increases the
= .00101
exponent size by one.
00101000000000000000000
• Every position moved to the right decreases Step4: exponent +127 = 4+127 = 131 to binary =
the exponent size by one. 10000011
• The initial exponent is 0. Store this in bits 23-30 (8 bits)
3. Remove leading 1 (the whole part of the fraction) Step 5: The number is positive store 0 in bit 31 to
from resulting binary number and store the rest of indicate positive.
the binary digits in bits 0-22.
4. Add 127 to exponent and store binary
representation of exponent in bits 23-30
1b 8b 23b
5. Store sign in bit 31, 1 for negative, 0 for positive.
0 10000011 00101000000000000000000
CPT11 1
5/8 = 0.625
Decimal to 32 bit floating point 0.625x2=1
0.25 x2 =
1. Change absolute value of the decimal number
0.5x2 =1
to binary
0.625 to bi
2. Write the binary in normalized form (i.e
scientific notation ) by moving radix point so
there is only a single 1 bit to the left of the radix
point.
• Every position moved to the left increases
the exponent size by one.
• Every position moved to the right
decreases the exponent size by one.
• The initial exponent is 0.
3. Remove leading 1 (the whole part of the
fraction) from resulting binary number and
store the rest of the binary digits in bits 0-22.
4. Add 127 to exponent and store binary
representation of exponent in bits 23-30
5. Store sign in bit 31, 1 for negative, 0 for
positive.
CPT11 1
32 bits Floating Point to Decimal
1.
Example
Check bit MSB (31) for sign, 1 decimal and add correct sign
1011111101000000000000000000000
negative, 0 positive
2. Extract bits 30 – 23 (the next 8 bits), sign exponent fraction
and find their value in decimal then
subtract 127 to get the exponent • Sign is 1 – number is negative.
3. Extract bits 22 – 0 and add implicit • Exponent field is 01111110 = 126 (decimal). =126-127=
bit with value 1 (as whole ) and the • Fraction is 0.100000000000… = 0.5 (decimal).
bit 0 to 22 as the fractional part
Value = -1.1000 x 2(126-127) = -1.100.. x 2-1
4. Change value of exponent to 0 by
shifting radix point of fractional part = -.1100 = -0.75.
right or left to reduce exponent.
5. Convert resulting binary number to
1x2-1 +!x2-2 = 1100.
0.5= 1/4 + 1/2 =
0.75=25. +
CPT11 1
32 bit floating point to decimal
1. Check bit MSB (31) for sign, 1 decimal and add correct sign
negative, 0 positive
2. Extract bits 30 – 23 (the next 8 bits),
and find their value in decimal then
subtract 127 to get the exponent
3. Extract bits 22 – 0 and add implicit
bit with value 1 as whole and the
bit 0 to 22 as the fractional part
4. Change value of exponent to 0 by
shifting radix point of fractional part
right to reduce exponent.
5. Convert resulting binary number to
CPT11 1
32 bit floating point to decimal
1. Check bit MSB (31) for sign, 1 negative, 0 decimal and add correct sign
positive = - 1.00101 .23= - 9.25
2. Extract bits 30 – 23 (the next 8 bits), and
find their value in decimal then subtract
127 to get the exponent
3. Extract bits 22 – 0 and add implicit bit
with value 1 as whole and the bit 0 to 22
as the fractional part
4. Change value of exponent to 0 by
shifting radix point of fractional part
right or left to reduce exponent.
5. Convert resulting binary number to
CPT11 1
32 bit floating point to decimal
1. Check bit MSB (31) for sign, 1 negative, 0 decimal and add correct sign
positive
2. Extract bits 30 – 23 (the next 8 bits), and
find their value in decimal then subtract
127 to get the exponent
3. Extract bits 22 – 0 and add implicit bit
with value 1 as whole and the bit 0 to 22
as the fractional part
4. Change value of exponent to 0 by
shifting radix point of fractional part
right or left to reduce exponent.
5. Convert resulting binary number to
CPT11 1
Textcharacters
• ASCII: Maps 128 ASCII Characters
to 7-bit code. For both printable and non-
printable (ESC, DEL, …) characters
CPT11 1
Interesting Properties of ASCII Code
• What is relationship between a decimal digit ('0', '1', …)
and its ASCII code?