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
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