Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

either of these guidelines may result in immediate failure of the course 1. [251 Suppose we number the bytes in a 32-bit word from 0

image text in transcribed

image text in transcribed

either of these guidelines may result in immediate failure of the course 1. [251 Suppose we number the bytes in a 32-bit word from 0 (least significant) to 3 (most significant). Write code for the following C function that will return an unsigned int consisting of byte 3 x and bytes 2 through 0 from y unsigned int combine (unsigned int x, unsigned int yl; Here are some test runs: combine (0x12345678, 0xABCDEFOD): 0x12CDEFO combine (0xABCDEFOO, 0x12345678) 0xAB345678 Use only bitwise operators; no if statements, loops, or arithmetic operators (+,-,-, %). Also write a main) function to test your function. Hint: use a bit mask to isolate byte 3 from x, and another bit mask to isolate bytes 2 through 0 from y, then combine the results. Comment your code, including every line that uses a bitwise operator. Name your source file 1 1.c 2. [251 Suppose we again number the bytes in a 32-bit word from O (least significant) to 3 (most significant). Write code for the following C function that will return an unsigned int such that byte iof x is replaced by byte b: unsigned int replace (unsigned int x, int i, unsigned char b); Here are some test runs: replace (0x12345678, 2, 0xAB0x12AB5678 replace (0x12345678, 0, 0xAB) 0x123456AB Use only bitwise operators; no if statements, loops, or arithmetic operators (+,-,-, %). Also write a main) function to test your function Hint: use shifts to align the input byte and a mask to isolate the bytes that should remain Comment your code, including every line that uses a bitwise operator, Name your source file 1 2.c 3. [251 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 1 if x has at least one bit with a value of 1 at an even index (including index 0), O otherwise: int evenBit(unsigned int x; Here are some test runs: evenBit (0x11 evenBit (0x31 evenBit (0x4:1 evenBit (0xFFFFEFEF)1 evenBit (OXAAAAAAAA) 0 evenBit (0x55555555):1 Use only bitwise and logical operators (&&, II, !; no if statements, loops, arithmetic operators (+,-, *./, %), or conditional operators (ze, ! , etc). Also write a main() function to test your function. Hint: use a bit mask to isolate the even bits, and think about the effect of a logical not (or two) on an int in C. Comment your code, including every line that uses a bitwise operator, Name your source file 1 3.C 4. [25] Consider the following C code: Hint: use a bit mask to isolate the even bits, and think about the effect of a logical not (or two) on an int in C. Comment your code, including every line that uses a bitwise operator. Name your source file 1 3.C 4. [25] Consider the following C code #include void printBytes (unsigned char *start, int len printf{" .2 x", start[1)); printf "n") void print Int (int x) { printBytes {(unsigned char *) &, sizeof(int)); void printFloat (float x) printBytes ( (unsigned char , sizeof (float)) Copy and paste the above code into a file named 1-4.c. Add the following functions to the file, taking the indicated data type as a parameter and calling printBytes as appropriate: printShort, printiong, printDouble Also write a main() function to test each of the above functions (with the exception of printBytes, which you do not need to test directly) with reasonable inputs. Do you notice anything unexpected regarding the output of your test functions? List any observations as comments inline in your main function and explain these observations based on your readings from the textbook. Zip the source files and solution document (if applicable), name the zip file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions