2/28/06: In Question 2, treat the number as unsigned fixed number.
should therefore be int instead of unsigned. The code has been updated to reflect the change.
In this homeworkd, we use the notation fixed<w,b> to denote a w bits fixed point number with binary point at position b from the least significant bit (counting from 0). For example, fixed<32,3> denotes a 32-bit fixed point number, of which 3 right most bits are fractional.
P&H Exercise 3.30.
What does the bit pattern from Question 1 represents for a fixed<32,3>?
What does the bit pattern from Question 1 represents for a fixed<32,32>?
What does the bit pattern from Question 1 represents for a fixed<32,0>?
Show the IEEE-754 binary representation for the following decimal floating-point numbers:
- 20.5
- -2.625
- 3 * 2-145
- -0
- +0
Show the binary representation for the following fixed-point fixed<8,3> numbers. Truncate bits that are not representable.
- 20.5ten
- 2.33ten
- 0.6875ten
OPTIONAL: What is the result if "even rounding" instead of truncation is used.
Complete the following C-function that converts a floating point number num into a fixed point number of type fixed<32,bp>. You may truncate all bits that are not representable.:
int Float2Fixed(float num, int bp) { int result; /* your code goes here */ return result; }
For example, Float2Fixed(5.5, 2) should return the integer 22 with bit pattern:
0000000000000000000000000000000000010110
Your solution to Question 1 to 4 should be saved in a file hw5.txt. Your solution to Question 5 should be saved in a file named hw5q5.c. From the directory that contains these two files, run:
submit hw5