Question: Assumptions Integers are 64-bits long and represented in twos-complement form. Right shifts of signed data are performed arithmetically. Forbidden Casting, either explicit or implicit. Relative
Assumptions
Integers are 64-bits long and represented in twos-complement form.
Right shifts of signed data are performed arithmetically. Forbidden
Casting, either explicit or implicit. Relative comparison operators (<, >, <=, and >=).
Division, modulus, and multiplication. Conditionals(if or ? :), loops, switch statements, function calls, and macro invocations.
Casting, either explicit or implicit. Legal Operations
Each problem has a list of which operations you are allowed to utilize
Even with these rules, you should try to make your code readable by choosing descriptive variable names and using comments to describe the logic behind your solutions. As an example, the following code extracts the most signi cant byte from integer argument x:
/* Get most significant byte from x */
int get_msb(int x) {
/* Shift by w-8 */
int shift_val = (sizeof(int)-1)<<3;
/* Arithmetic shift */
int xright = x >> shift_val;
/* Zero all but LSB */ return xright & 0xFF;
}
2.Write code for the function with the following prototype:
/*
* byteSwap - swaps the nth byte and the mth byte
* Examples: byteSwap(0x12345678, 1, 3) = 0x56341278 * byteSwap(0xDEADBEEF, 0, 2) = 0xDEEFBEAD
* You may assume that 0 <= n <= 3, 0 <= m <= 3
* Legal ops: ! ~ & ^ | + << >>
* Your code should conform to the rules listed above
*/
int byteSwap(int x, int n, int m) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
