c语言int num1=1,C语言一题

070d6550041e5346c13283420b7fb91e.png

为了方便大家辨别,我人肉OCR一下。

2.71:

You just started working for a company that is implementing a set of procedures

to operatate 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 arithemetic right shifts with

following prototype:

/* Declaration of data type where 4 bytes are packed

into an unsigned */

typedef unsigned packet_t;

/* Extract byte from word. Return as signed integer */

int xbyte(packet_t word, int bytenum);

That is, the function will extract the designed byte and sign extend it to be a

32-bit int.

Your predecessor (who was fired for incompetence) wrote following cod

/* Failed attempt at xbyte */

int xbyte(packet_t word, int bytenum)

{

return (word >> (bytenum <

}

A. What is wroing with this code?

B. Give a correct implementation of the function that uses only left and righ

shifts, along with one subtraction.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值