gpt4 book ai didi

c - 用无符号整数中的另一个字节替换第 n 个字节

转载 作者:太空宇宙 更新时间:2023-11-04 01:51:23 25 4
gpt4 key购买 nike

我想用b替换a的字节。

unsigned int a = 0x12dc4430;
unsigned char b = 0xcb;

如何用 b 替换 a 的第 1 个和第 3 个字节?

像这样:对于第一个有效字节

12dc33cb

第三个有效字节

12cb4430 

最佳答案

不确定“第一个和第三个字节”是什么意思,但假设您指的是最重要的字节和第三个最重要的字节:

unsigned int a = 0x12dc4430;
unsigned char b = 0xcb;
a = (a & 0x00ff00ff) | (b << 8) | (b << 24);
printf("%x\n", a);

打印 cbdccb30

关于c - 用无符号整数中的另一个字节替换第 n 个字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42358004/

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