Data Lab: Manipulating Bits

Download Report

Transcript Data Lab: Manipulating Bits

Data Lab: Manipulating Bits
Introduction
• Purpose: To be more familiar with bit-level
representations of integers and floating
point numbers.
• Individual project
• Programming environment
– Linux server: 117.16.244.185
– Telnet & login with your ID & password
Handout instructions
•
Start by copying datalab-handout.tar to a directory using the command
cp /var/share/datalab-handout.tar .
tar xvf datalab-handout.tar
– This will cause a number of files to be unpacked in the directory.
– The only file you need to modify is bits.c.
•
bits.c
– Contains a skeleton for 15 programming puzzles.
– You must complete each function skeleton using only straight-line code for integer
puzzles (no loops or conditionals).
– Only allowed 8 operators: ! ~ & ^ | + << >>
– You are not allowed to use any constants longer than 8 bits.
Puzzles
• Bit manipulations
– Rating: difficulty (also the number of points)
– Max ops: the maximum number of operators
allowed to use to implement each function
Puzzles
• Two’s complement arithmetic
Puzzles
• Floating-point operations
– You can used standard control structures (loops, conditionals).
– You may use both int and unsigned data types, including arbitrary
integer and unsigned constants.
– You may not use union, struct, or array.
– Any floating point operand will be passed to the function as having
type unsigned, and any returned floating point value will be of type
unsigned.
– float_neg & float_twice must handle the full range of possible
argument values including NaN and infinity.
Helper programs
• fshow
– Helps you understand the structure of floating
point numbers.
– You can use fshow to see that an arbitrary
pattern represents as a floating point number
– Example
# ./fshow 2080374784
Floating point value 2.658455992e+36
Bit Representation 0x7c000000, sign = 0, exponent = 0xf8, fraction = 0x000000
Normalized. +1.0000000000 X 2^(121)
• ishow
– Helps you understand the structure of integer
numbers.
Compile
• Switch to the handout directory and type
make
Evaluation
• Correctness points: 41
– By executing btest, points are automatically evaluated.
• Performance points: 30
– 2 points for each function satisfying the operator limits.
– dlc is used to evaluate the number of operators.
• Bonus points: 6
– Student(s) who implement the functions bitCount, ilog2,
and float_i2f with the smallest number of operators will
be given 2 points.
– A student may get 6 bonus points at maximum.
– The number of operators should be smaller than the
operator limits.
– It should be done during the Lab time.