324_Book

# In this chapter we will learn the details of a

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: s. C. Modify the code to run properly on any machine for which int’s are at least 16 bits. Homework Problem 2.37 [Category 1]: You just started working for a company that is implementing a set of procedures to operate on a data structure where four signed bytes are packed into a 32-bit unsigned. Bytes within the word are numbered from 0 (least signiﬁcant) to 3 (most signiﬁcant). You have been assigned the task of implementing a function for a machine using two’s complement arithmetic and arithmetic right 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 ﬁred for his incompetence) wrote the following code: /* Failed attempt at xbyte */ int xbyte(packed_t word, int bytenum) { return (word &gt;&gt; (bytenum &lt;&lt; 3)) &amp; 0xFF; }...
View Full Document

## This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online