1. Engineering
  2. Computer Science
  3. 2 20 suppose we number the bytes in a 32bit...

Question: 2 20 suppose we number the bytes in a 32bit...

Question details

2. [20] Suppose we number the bytes in a 32-bit word from 0 (least significant) to 3 (most significant) and that the word consists of 4 individual signed bytes. Write code for the following C function that will return byte i of x sign extended to 32 bits: unsigned int extract (unsigned int x, int i); Here are some test runs: extract (0x12345678, 0) 0x00000078 extract (0xABCDEF00, 2) 0xFFFFFFCD Use only bitwise operators and subtraction; no if statements, loops, or other arithmetic operators (+, *, /, %). Also write a main() function to test your function. Hint: arithmetic shift is your friend with regard to sign extension. Name your source file 2-2.c

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution