Answered step by step
Verified Expert Solution
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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started