C programming homework

profileyxb390
hw2-2.html

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <HEAD> <TITLE>CSC 373 Sections 601,610 Spring 2014 Homework Assignment 2 </TITLE> </HEAD> <body> <center> <h3><b>CSC 373 Sections 601,610 Spring 2014<BR> Homework Assignment 2</B></h3> Due: <b>Tuesday, April 22</b></center> <BR><BR> This assignment is worth 10% of your total grade. <p>Your assignment is to write 5 C functions, which perform low-level bit operations on integers. Please place your 5 functions in a file called <code>bits.c</code>. Although you most likely will want to write a <code>main</code> function for the purposes of testing your code, do <b>not</b> submit <code>bits.c</code> with a <code>main</code> function in it. Place a comment at the beginning of your file with your name in it. <p> Each function is worth 20 points. Each function must conform to the following style: <xmp> int Funct(arg1, arg2, ...) { /* brief description of how your implementation works */ int var1 = Expr1; ... int varM = ExprM; varJ = ExprJ; ... varN = ExprN; return ExprR; } </xmp> Each "Expr" is an expression using ONLY the following: <ol> <li> Integer constants 0 through 255 (0xff), inclusive. You are not allowed to use big constants such as 0xffffffff. <li> Function arguments and local variables (no global variables). <li> Unary integer operations ! ~ <li> Binary integer operations & ^ | + << >> </ol> <p> Some of the problems restrict the set of allowed operators even further, although you might not use all of the operators that are specified. Each "Expr" may consist of multiple operators. You are not restricted to one operator per line. <p> You are expressly forbidden to: <ol><li> Use any control constructs such as if, do, while, for, switch, etc. <li> Define or use any macros. <li> Define any additional functions in this file. <li> Call any functions. <li> Use any other operations, such as &&, ||, -, or ?: <li> Use any form of casting. <li> Use any data type other than <code>int</code>. This implies that you cannot use arrays, or structures. </ol> <p> You may assume that your machine: <ol> <li>Uses 2s complement, 32-bit representations of integers. <li>Performs right shifts arithmetically (not logically). <li>Has unpredictable behavior when shifting an integer by more than the word size. </ol> <p>Here are the functions that you must implement: <ol> <p><li><code>int bitAnd(int x, int y)</code>:&nbsp;&nbsp; computes a <b>bitwise and</b> of <code>x</code> and <code>y</code>, using only the C <code>~</code> and <code>|</code> operators. <p><li><code>int bitXOr(int x, int y)</code>:&nbsp;&nbsp; computes a bitwise exclusive-or of <code>x</code> and <code>y</code>, using only the C <code>~</code>, <code>&</code>, and <code>|</code> operators. <p><li><code>int isPositive(int x)</code>:&nbsp;&nbsp; returns non-zero (true) if <code>x</code> is positive, or 0 (false) if <code>x</code> is 0 or negative. You are allowed to use these C operators:&nbsp;&nbsp; <code>! ~ & ^ | + &lt;&lt; &gt;&gt; </code> <p><li><code>int negate(x)</code>:&nbsp;&nbsp;returns <code>-x</code>. You are allowed to use these C operators:&nbsp;&nbsp; <code>! ~ & ^ | + &lt;&lt; &gt;&gt; </code> <p><li><code>int getByte(int x, int n)</code>:&nbsp;&nbsp; extracts byte <code>n</code> from <code>x</code>. Bytes are numbered from 0 (the least significant, or rightmost, byte) to 3 (the most significant, or leftmost, byte). You are allowed to use these C operators: <code>! ~ & ^ | + &lt;&lt; &gt;&gt; </code> </ol> <br><br><br><br><br><br><br><br><br><br></BODY> </HTML>