Reference no: EM132194453
Write a 'c' code for the following puzzles,
Bit Manipulations Table 1 describes a set of functions that manipulate and test sets of bits. The "Points" field gives the number of points for the puzzle, and the "Max ops" field gives the maximum number of operators you are allowed to use to implement each function. See the comments in bitslab.c for more details on the desired behavior of the functions.
Name Description Points Max Ops
bitAnd(x,y) x & y using only | and ˜ 2 8
getByte(x,n) Get byte n from x. 2 6
logicalShift(x,n) Shift right logical. 3 20
bitCount(x) Count the number of 1's in x. 4 40
bang(x) Compute !x without using ! operator. 4 12
Two's Complement Arithmetic Table 2 describes a set of functions that make use of the two's complement representation of integers. Again, refer to the comments in bitslab.c for more information.
Name Description Points Max Ops
tmin() Most negative two's complement integer 1 4
fitsBits(x,n) Does x fit in n bits? 2 15
divpwr2(x,n) Compute x/2 n 2 15
negate(x) -x without negation 2 5
isPositive(x) x > 0? 3 8
isLessOrEqual(x,y) x <= y? 3 24
Floating-Point Operations For this part of the assignment, you will implement some common single-precision floating-point operations.
In this section, you are allowed to use standard control structures (conditionals, loops), and you may use both int and unsigned data types, including arbitrary unsigned and integer constants.
You may not use any unions, structs, or arrays. Most significantly, you may not use any floating point data types, operations, or constants.
Instead, 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. Your code should perform the bit manipulations that implement the specified floating point operations.
Table 3 describes a set of functions that operate on the bit-level representations of floating-point numbers. Refer to the comments in bits.c for more information.
Name Description Points Max Ops
float_neg(uf) Compute -f 4 10
float_i2f(x) Compute (float) x 4 30
float_twice(uf) Computer 2*f 4 30