CS:APP
renzhenmac
全部博文(24)
2009年(24)
迷惑的风
wzzushx
HughNian
gaopengt
fox1955
Tjie_S
aku1
enenshiw
hanzhenl
分类: C/C++
2009-08-07 17:56:27
// 替换unsigned int中的某一指定byte#include<iostream>using namespace std;unsigned replace_byte(unsigned x, int i, unsigned char b){cout << hex << (unsigned)b << endl;unsigned ub = (unsigned)b;unsigned ubp = ub << i*8;unsigned mask = ~(0xff << i*8);return (unsigned)((x&mask) | ubp);}int main(){cout << "0x" << hex << replace_byte(0x12345678, 2, 0xAB);return 0;}
上一篇:CSAPP 习题2.49 unsigned_high_prod
下一篇:show_bytes的C++版本
登录 注册