1. Engineering
  2. Computer Science
  3. winter 19 cis 314 assignment 2 100100 points due...

Question: winter 19 cis 314 assignment 2 100100 points due...

Question details

Winter 19 CIS 314 Assignment 2- 100/100 points - Due Wednesday, 1/23, 11:59 PM Please submit individual source files for coding exercises (see naming conventions below) and a single solution document for non-coding exercises (txt or pdf only). Your code and answers need to be documented to the point that the graders can understand your thought process. Full credit will not be awarded if sufficient work is not shown. 1. 20 Suppose we number the bits in a 32-bit word from 0 (least significant) to 31 (most significant). Write code for the following C function that will return a bit mask containing 1s for the least-significant n bits and Os for the remaining most-significant bits: int mask(int n); Your solution will need to handle values of n on the range [1, 31] (i.e., 1 up to, and including, 31) Here are some test runs: mask(1 0x1 mask (2): 0x3 mask (3): 0x7 mask (5) 0x1F mask (8): 0xFF mask (16) 0xFEFF mask (31) 0x7FFFFFFF Use only bitwise operators and subtraction; no if statements, loops, or other arithmetic operators (+, *, /, %). Also write a main() function to test your function. Hint: you can use subtraction on this one- please do. Name your source file 2-1.c 2. [20] Suppose we number the bytes in a 32-bit word from 0 (least significant) to 3 (most significant) and that the word consists of 4 individual signed bytes. Write code for the following C function that will return byte i of x sign extended to 32 bits: unsigned int extract (unsigned int x, int i) Here are some test runs extract (0x12345678, 0) 0x00000078 extract (0xABCDEF00, 2): 0xEFFFFFCD Use only bitwise operators and subtraction; no if statements, loops, or other arithmetic operators (+, *, /, %). Also write a main() function to test your function. Hint: arithmetic shift is your friend with regard to sign extension. Name your source file 2-2.c

Name your source file 2-2.c 3. [15] Fill in the missing expression in the following C code such that it will return 1 if x isy 0 otherwise (you can assume that neither argument is NaN and that +0.0 and -0.0 are considered equal) int le(float x, float y) unsigned int ux(unsigned int &x) 1/ convert raw bits unsigned int uyunsigned int &y) /I convert y raw bits un signed int sx = ux >> 31; // extract sign bit of ux unsigned int sy = uy >> 31; // extract sign bit of uy ux <<= 1; // drop sign bit of ux uy <<= 1; // drop sign bit of uy // TODO: return using sx, sy, ux, uy Here are some test runs: le (0.0f, 0.0f): 1 le (-0.of, 0.0f) 1 le (-1.0Of, 1.0f): 1 le (1.0f, 1.0E) 1 le (-1.Of, 0.0f) 1 le (0.0f, 1.0f): 1 le(1.0f, 0.0f); le (0.0f, -1.0f): 0 Use only bitwise, logical, and relational, , <, <, >,) operators; no if statements, loops, or arithmetic operators (+,-, *, /, %). Also write a main() function to test your function. Hint: youre going to want to or together all of the cases in which the function will return 1. For example, (ux0 && uy0) will be true only if x is either +0.0f or -0.0f and y is either +0.0f or -0.0f Name your source file 2-3.c 4. [15] Convert the following hex values to decial assuming that they are stored as 32-bit 2s complement integers. a. (5) 0x000000C4 b. (5) OxFFFFFEC4 c. (5) 0xFFFFFFFF Write your answers in your solutions document. Show your work. 5. [15] Convert the following hex values to decimal assuming that they are encoded as IEEE 754 single-precision floating-point numbers: a. (5) 0xBF800000 b. (5) 0x3FC00000 c. (5) 0x42C80000 Write your answers in your solutions document. Show your work.

6. [15] Convert the following decimal numbers to hex encoded as IEEE 754 single-precision floating-point numbers. Write your answers in your solutions document. b. (5) -10.25 c. (5) 314.25 Write your answers in your solutions document. Show your work. Zip the source files and solution document (if applicable), name the .zip file <Your Full Name>Assignment2.zip (e.g., EricWillsAssignment2.zip), and upload the .zip file to Canvas (see Assignments section for submission link).

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution