gpt4 book ai didi

c++ - 4 个有符号字节打包成 32 位无符号

转载 作者:行者123 更新时间:2023-11-28 01:04:02 26 4
gpt4 key购买 nike

// Declaration of data type where 4 bytes are packed into an unsigned.   
int xbyte(packed_t word, int bytenum);

int main()
{
int bytenum = 0;
typedef unsigned packed_t;
packed_t word;
}

// Extract byte from word, return as signed integer.
int xbyte(packed_t word, int bytenum)
{
// Failed attempt at xbyte
return ( word >> (bytenum << 3)) & 0xff;
}

我不确定如何在这个问题中声明 packed_t。我应该从顶部使用原型(prototype)。单词是如何发挥作用的。我迷路了,这是家庭作业的一部分。

最佳答案

您已经有了一个 typedef 行。让它成为这段代码的第一行,你就完成了。最基本的是 typedefed 名称必须在您使用它的任何地方可见。

关于c++ - 4 个有符号字节打包成 32 位无符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7315752/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com