Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

B) (4 Points) Consider a scenario where 4 signed bytes are stored into a 32-bit unsigned integer number. Remember, bytes within a word are numbered

B) (4 Points) Consider a scenario where 4 signed bytes are stored into a 32-bit unsigned integer number. Remember, bytes within a word are numbered from 0 (least significant byte or LSB) to 3 (most significant byte or MSB). Now consider the following function

: int extractSignedByte(unsigned word, int byte_number) {

return (word >> (byte_number << 3)) & 0xFF;

}

This function should extract the designated byte and sign extends it to a 32-bit integer. However, a bug exists that prevents this function from performing the correct task. (1) (2 Points) What is the bug in this code and why do you think it can cause the function to return the wrong result, and (2) (2 Points) by using only left and right shifts, and one subtraction, replace the buggy code inside the extractSignedByte function with the correct implementation that will always cause the function to return the desired signed byte as a signed 32-bit integer. Please explain your implementation in few words. Hint: remember that right shifts of unsigned numbers are performed logically and right shifts of signed numbers are performed arithmetically. Refer to Practice Problem 2.23 in the book for additional help

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

What is a NIC? What is a hub?

Answered: 1 week ago