具体题目如下:/* * getByte - Extract byte n from word x* Bytes numbered from 0 (LSB) to 3 (MSB)* Examples:getByte(0x12345678,1) = 0x56* Legal ops:& ^ | + >* Max ops:6*/int getByte(int x,int n) {return 2;}

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/05 02:58:57

具体题目如下:
/*
* getByte - Extract byte n from word x
* Bytes numbered from 0 (LSB) to 3 (MSB)
* Examples:getByte(0x12345678,1) = 0x56
* Legal ops:& ^ | + >
* Max ops:6
*/
int getByte(int x,int n) {
return 2;
}

从词x中取出第n(0~3)字节.
示例:从0x12345678中取出第1字节.
其中78是第0字节,56是第一字节,34是第二字节,12是第三字节,因为要求第一字节,所以取出0x56.
答案:
int getByte(int x,int n){return((x (8* n));}