我试图从一个 16 位字中提取两个字节,并从两个字节中生成一个 16 位字。这是我尝试过的(byte = unsigned char, word = unsigned short):
将 grpix 字拆分为 2 个字节:
word grpix; // Assume that the value has been initialized
byte grpixl = grpix & 0x00FF;
byte grpixh = grpix & 0xFF00;
从 2 个字节制作 grpix 字
byte grpixh; // Assume that the value has been initialized
byte grpixl; // Assume that the value has been initialized
word grpix = grpixh;
grpix <<= 8;
grpix += grpixl;
出于某种原因,我的代码没有按预期工作,现在我不确定单词的“拆分”是否错误,单词的“制作”是否错误,或两者兼而有之......你能给我有什么建议吗?