#include<stdio.h> unsignedreplace_byte(unsigned x, int i, unsignedchar b) { x = x & (~(0XFF << (i << 3)));//相应字节置零 x = x | (b << (i << 3)); //相应字节改为char b return x; } intmain() { unsigned ret = replace_byte(0X12345678, 1, 0XAB); printf("0X%X\n", ret); return0; }