Question: A) (6 Points) Consider a w-bit unsigned value/word where bytes are numbered from 0 (lease significant byte or LSB) to w/8 1 (most significant byte

A) (6 Points) Consider a w-bit unsigned value/word where bytes are numbered from 0 (lease significant byte or LSB) to w/8 1 (most significant byte or MSB). Implement the following two C functions which both replace the byte at index i with the byte b. replace_byte_inline should operate on the original value without creating any new local variables (call by reference), whereas replace_byte should operate on a new local unsigned value x call by value and returns an unsigned value as the result. For instance, replace_byte(0x12345678, 2, 0xAB) should return 0x12AB5678 and replace_byte(0x12345678, 0, 0xAB) should return 0x123456AB. Explain both of your implementations in few words. See below for additional requirements while implementing both functions.

1) (3 Points) void replace_byte_inline(unsigned char *x, int i, unsigned char b); This function should operate on the original unsigned value without creating any new local variables that will hold the value x call by reference and must not utilize any bit-level, logic, shift, or arithmetic operations.

2) (3 Points) unsigned replace_byte (unsigned x, int i, unsigned char b); This function should operate on a new local unsigned value x call by value and returns an unsigned value as the result. In addition, you must only use one or more bit-level and/or shift operations in your implementation (arithmetic and logic operations cannot be used). Hint: this can be considered as another bit masking problem.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!