Principles of Programming Languages
Data Type
Question 1.
A floating point number type is stored based on IEEE 754 standard: Value of the number
is represented by 9 bits, the first bit is sign bit (1 for negative and 0 for positive). The next
three bits are used for exponent and the last five are for the fraction.
A. Convert binary floating points to decimal numbers
100101100
001010000
B. Convert decimal numbers to binary floating point numbers
1.25
-11.25
1
Principles of Programming Languages
Question 2.
What is the size of the following record written in Pascal?
type sample = record
a : integer ;
b : string [ 1 5 ] ;
c : set of 1 . . 3 2 ;
case r e s u l t : boolean of
true : ( d : r e a l ; e : integer ) ;
f a l s e : ( g : array [ 1 . . 2 ] of integer ) ;
end ;
where a string has 1 byte descriptor to keep the actual length, and the sizes of integer, real,
char, boolean are 2, 4, 1 and 1, respectively. The set is implemented by a bit vector.
2
Principles of Programming Languages
Question 3.
What is the size of the record given in question 3 if data alignment is applied? Rearrange
the components of the record to have lower size?
3
Principles of Programming Languages
Question 4.
Draw the storage block with the first five elements of the following vector, in case i) columnmajor; ii) row-major
A. A: Array [-2..1,3..5] of real;
B. A: Array [-1..1,-2..0] of integer;
4