Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Representation - Part II. Characters A variable may not be a non-numerical type Character is the most common non- numerical type in a programming.

Similar presentations


Presentation on theme: "Data Representation - Part II. Characters A variable may not be a non-numerical type Character is the most common non- numerical type in a programming."— Presentation transcript:

1 Data Representation - Part II

2 Characters A variable may not be a non-numerical type Character is the most common non- numerical type in a programming language When a key is pressed on the keyboard a unique representation of the key is transmitted to the computer ASCII 1 assigns unique representations to 128 characters (see page 102 of the text) 1 American Standard for Computer Information Interchange

3 While the characters are not numbers, their unique representations are 7-bit unsigned binary representation The representations allow programmers to easily compare characters using equality or relational operators (e.g., >, <= ) An operation that can take advantage of how the ASCII representation are arranged is sorting.

4 Example 10.1 (char integer) moveint 0 getch procch:bgt ch,’9’,notadigit blt ch,’0’,notadigit subch,ch,’0’ mul int,int,10 add int,int,ch getch bprocch notadigit: Check that the character read is a digit Convert into decimal

5 Floating Point Representation The IEEE Floating Point Standard (FPS) is a widely used floating point representation from among the many alternative formats The representation for floating point numbers are broken into two parts:  mantissa (variant of a scaled, sign magnitude integer)  exponent (8-bit, biased-127 integer) 1 +

6 A number N represented in floating point is determined by the mantissa m and an exponent e N = (-1) s * m * 2 e If the sign of the mantissa is negative, s = 1 ; if the sign of the mantissa is positive, s = 0. The mantissa is normalized, i.e., 1  m < 2 In the FPS format, the precision is specified as 24 bits thus m = 1.f 22 f 21 …f 1 f 0 1 +

7 Conversion to Floating Point Representation 1.Break the decimal number into two parts: an integer and a fraction 2.Convert the integer into binary and place it to the left of the binary point 3.Convert the fraction into binary and place it to the right of the binary point 4.Write it in scientific notation and normalize

8 Example 10.2 Convert 22.625 to floating point representation 1. Convert 22 to binary. 22 10 = 10110 2 2. Convert.625 to binary 2*.625= 1 +.25 2*.25 = 0 +.5 2*.5= 1 + 0 3. Thus 22.625 10 = 10110.101 2 4. In scientific notation: 10110.101*2 0 Normalized form: 1.0110101*2 4.625 10 =.101 2

9 IEEE FPS Representation Given the floating point representation N = (-1) s * m * 2 e where m = 1.f 22 f 21 …f 1 f 0 we can convert it to the IEEE FPS format using the relations: F = (m-1)*2 n E =e + 127 S =s SEF

10 Single-Precision Floating Point The IEEE FPS single precision format has 32 bits distributed as 0  E  255, thus the true exponent e is restricted so that -126  e  127 SEF 1 823 F = fractional part of the significand

11 Zero and the Hidden bit In IEEE FPS, zero is represented by setting E = F = 0 regardless of the sign bit, thus there are two representations for zero: +0 and -0. +  by S=0, E=255, F=0 -  by S=1, E=255, F=0 NaN or Not-a-Number by E=255, F  0 (may result from 0 divide by 0) The leading 1 in the fraction is not represented. It is the hidden bit.

12 Converting to IEEE FPS 1.Convert into a normalized floating point representation 2.Bias the exponent. The result will be E. 3.Put the values into the correct field. Note that only the fractional part of the significand is placed into F.

13 Example 10.3 Convert 22.625 to IEEE FPS format (single precision) 1. In scientific notation: 10110.101*2 0 Normalized form: 1.0110101*2 4 2. Bias the exponent: 4 + 127 = 131 131 10 = 10000011 2 3. Place into the correct fields. S = 0 E = 10000011 F = 011 0101 0000 0000 0000 0000 100000110 SE F 01101010000000000000000

14 Example 10.4 Convert 17.15 to IEEE FPS format (single- precision) 17.15 10 = 10001.0010 0110 0110 0110 011*2 0 1. Normalized form: 1. 0001 0010 0110 0110 0110 011 * 2 4 2. Bias the exponent: 4 + 127 = 131 131 10 = 10000011 2 3. Place into the correct fields. S = 0 E = 10000011 F = 00010010011001100110011 00010010011001100110011100000110 SE F

15 Example 10.5 Convert -83.7 to IEEE FPS format (single precision) 2*.7 = 1 +.4 2*.4 = 0 +.8 2*.8 = 1 +.6 2*.6 = 1 +.2 2*.2 = 0 +.4 2*.4 = 0 +.8 2*.8 = 1 +.6 2*.6 = 1 +.2 2*.2 = 0 +.4... -83.7 10 =-1010011.101100110 Note: this is in single-precision floating point representation format but not FPS format

16 1. In scientific notation: -1010011.101100110 * 10 0 Normalized form: -1.010011101100110 * 2 6 2. Bias the exponent: 6 + 127 = 133 133 10 = 10000101 2 3. Place into the correct fields. S = 1 E = 10000101 F = 01001110110011001100110 01001110110011001100110100001011 SE F


Download ppt "Data Representation - Part II. Characters A variable may not be a non-numerical type Character is the most common non- numerical type in a programming."

Similar presentations


Ads by Google