title |
---|
Data Lab |
datalab.pdf
datalab-handout.tar
- Run
tar xvf datalab-handout.tar
to unpack the project. - Modify
bits.c
to solve the puzzles. - Run
make
to build the project.- Install
gcc-multilib
(once only) iffatal error: bits/libc-header-start.h: No such file or directory
occurs.
- Install
- Run
To make the working directory clean, it is recommended to add btest
, fshow
and ishow
into a .gitignore
file.
tests.c
expresses the correct behavior of your functions.
fshow
(built from fshow.c
) helps you understand the structure of floating point numbers.
btest
(built from btest.c
) checks the functional correctness of the functions in bits.c
.
./btest -f bitXor # tests only a single function.
The executable dlc
is an ANSI C compiler that you can use to check for compliance with the coding rules for each puzzle.
./dlc bits.c # returns silently if there are no problems with your code.
./dlc -e bits.c # prints the number of operators used by each function.
The Perl script driver.pl
is a driver program that uses btest
and dlc
to compute the correctness and performance points for your solution.
## Grading:
./driver.pl
## Install required modules (once only):
apt install cpanminus # if `cpan` is not found
cpan App::cpanminus # recommended in CPAN docs
cpanm Getopt::Std # redundant, use as a check
(x == y) == (!(x ^ y)) ;
(x != y) == (!(!(x ^ y)));
(-x) == (~x + 1);
The minimum two's complement (32-bit) integer is
./ishow 0x80000000
Hex = 0x80000000, Signed = -2147483648, Unsigned = 2147483648
The maximum two's complement (32-bit) integer is
./ishow 0x7FFFFFFF
Hex = 0x7fffffff, Signed = 2147483647, Unsigned = 2147483647
The binary representation of 0xAA
is 10101010
.
x + y == 0
implies x + (y - 1) == 0xFFFFFFFF
.
0x30 <= x && x <= 0x39
== (x & 0xFFFFFF00 == 0)
&& (x & 0xF0 == 0x30)
&& (x & 0xF + 6 < 16);
int x_is_0 = !x ; /* x == 0 ? 0x00000001 : 0x00000000 */
x_is_0 = ~x_is_0; /* x == 0 ? 0xFFFFFFFE : 0xFFFFFFFF */
x_is_0 += 1; /* x == 0 ? 0xFFFFFFFF : 0x00000000 */
x <= y
== (x == 1 << 31)
|| (x < 0 && 0 <= y)
|| (!((x ^ y) & (1 << 31)) && 0 <= y - x)
Compress all bits to the least significant one.
If x < 0
, find the first 0
. Else, find the first 0
in ~x
.
If expotent == 0
, a single operation fraction << 1
will handle both cases:
- if the highest bit of
fraction
is0
, the last bit ofexpotent
will still be0
. - if the highest bit of
fraction
is1
, it will naturally be the last bit ofexpotent
.
int x |
float(pow(2, x)) |
---|---|
(INT_MIN, -149) |
0 |
[-149, -127] |
1 << (x + 149) |
(-127, +127] |
(x + 127) << 23 |
[+128, INT_MAX) |
0x7F800000 |