Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. You just started working for a company that is implementing a set of procedur

ID: 3888255 • Letter: 4

Question

4. You just started working for a company that is implementing a set of procedures to operate on a data structure where 4 signed bytes are packed into a 32-bit unsigned. Bytes within the word are numbered from 0 (least significant) to 3 (most significant). You have been assigned the task of implementing a function for a machine using two's-complement arithmetic and arithmetic right/left shifts with the following prototype: / Declaration of data type where 4 bytes are packed into an unsigned */ typedef unsigned packed.t; / Extract byte from word. Return as signed integer */ int xbyte(packed t word, int bytenum); That is, the function will extract the designated byte and sign extend it to be a 32-bit int Your predecessor (who was fired for incompetence) wrote the following code: /* Failed attempt at xbyte*/ int xbyte (packed t word, int bytenum) return (word >» (bytenum

Explanation / Answer

A). if the bytenum is 1 , it will shift the word by 8 bits which is wrong , the correct code should be

b) word >> ((bytenum-1) <<3 ) * 0XFF

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote