当前位置:网站首页>2.59-编写一个C表达式,它生成一个字,由x的最低有效字节和y中剩下的字节组成。对于运算数x =0x89ABCDEF和y=0x76543210,就得到0x765432EF.
2.59-编写一个C表达式,它生成一个字,由x的最低有效字节和y中剩下的字节组成。对于运算数x =0x89ABCDEF和y=0x76543210,就得到0x765432EF.
2022-04-22 21:49:00 【gan-di】
先列出表达式:
(x & 0xFF) | (y & ~0xFF)
#include <stdio.h>
//4 bytes as example;
int generate_a_word(int x, int y) {
int z = 0;
y = y&(~0xff);
x = x&0xff;
z = x|y;
return z;
}
int main() {
int x = 0x89ABCDEF;
int y = 0x76543210;
int z = generate_a_word(x, y);
printf("%#X\n", z);
return 0;
}

官方答案:
/** generate-a-word.c */
#include <stdio.h>
#include <assert.h>
int main(int argc, char* argv[]) {
size_t mask = 0xff;
size_t x = 0x89ABCDEF;
size_t y = 0x76543210;
size_t res = (x & mask) | (y & ~mask);
assert(res == 0x765432EF);
return 0;
}
版权声明
本文为[gan-di]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45861496/article/details/124325082
边栏推荐
- Reinforcement learning (practice): feedback, AC
- Want to day browser: recommend several easy-to-use desktop browsers
- 报名开启|QKE 容器引擎托管版暨容器生态发布会!
- Simple use of Muduo in Muduo source code analysis
- Leetcode 04 Median of Two Sorted Arrays
- Overview of working principle and main characteristics of ATOS proportional valve
- What is the lifecycle of automated testing?
- CDN功能特性问题
- 百思买Best Buy 网站EDI 测试流程
- 企业应如何制定云计算使用中的灾难恢复计划?
猜你喜欢

The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video

都是做全屋智能的,Aqara和HomeKit到底有什么不同?

r语言使用rjags R2jags建立贝叶斯模型

Overview of working principle and main characteristics of ATOS proportional valve

【零散知识点总结5】

强化学习(实践):DQN,Double DQN,Dueling DQN

东吴证券X袋鼠云:数据轻松可取、毫秒级反应能力,东吴证券做对了什么?

CDN功能特性问题

7. 堪比JMeter的.Net压测工具 - Crank 总结篇 - crank带来了什么

意大利阿托斯电磁阀的工作性质是什么?
随机推荐
What are the functional problems of UI testing?
TS classic type gymnastics: how to turn the joint type into the cross type? We need to know three points: distribution law, inversion position, inversion and covariance
Vulnerability utilization in 2021: 95% of traditional vulnerabilities have been disclosed
强化学习(实践):DQN,Double DQN,Dueling DQN
跨域问题及Umi-proxy代理解决跨域问题
Common commands of Linux
RPCX源码学习-client端
系列解读 SMC-R (二):融合 TCP 与 RDMA 的 SMC-R 通信 | 龙蜥技术
KunlunDB对MySQL私有DML语法的支持
快速计算约数的个数——从基础到高级
Series interpretation of smc-r (II): smc-r communication technology integrating TCP and RDMA
pcba/ IPQ6010 802.11ax 2x2 2.4G&5G /2.5Gbps Ethernet Port
Characteristics of Vickers Vickers proportional valve
Redux-Devtools安装
Function pointer and callback function
CDN功能特性问题
node 报错记录:Cannot find module are-we-there-yet\index.js
How should enterprises make disaster recovery plans for Cloud Computing?
阿里云日志服务sls的典型应用场景
来个 vue 大佬,看看有没有 iframe 缓存方案?