交换两个十六进制数的位置
来源:互联网 发布:数据库前置库怎么配置 编辑:程序博客网 时间:2024/06/13 20:58
#include <stdio.h>
#include <stdlib.h>
unsigned replace_byte(unsigned x, int i, unsigned char b)
{
unsigned temp=x;
unsigned long temp1 = (i+1)*8;//左移位数
int t1,t2;
t1 = (((x>>temp1)<<8)+(unsigned)b)<<(temp1-8);//左移
t2 = temp<<((4-i)*8)>>((4-i)*8);//右移
return t1|t2;
}
int main()
{
unsigned s;
s=replace_byte(0x12345678,2,0xAB);
printf("%x\n",&s);
s=replace_byte(0x12345678,0,0xAB);
printf("%x\n",&s);
return 0;
}
#include <stdlib.h>
unsigned replace_byte(unsigned x, int i, unsigned char b)
{
unsigned temp=x;
unsigned long temp1 = (i+1)*8;//左移位数
int t1,t2;
t1 = (((x>>temp1)<<8)+(unsigned)b)<<(temp1-8);//左移
t2 = temp<<((4-i)*8)>>((4-i)*8);//右移
return t1|t2;
}
int main()
{
unsigned s;
s=replace_byte(0x12345678,2,0xAB);
printf("%x\n",&s);
s=replace_byte(0x12345678,0,0xAB);
printf("%x\n",&s);
return 0;
}
阅读全文
0 0
- 交换两个十六进制数的位置
- 交换两个数的位置
- 交换两个数的位置
- 引用 交换两个数的位置
- 精彩百例:交换两个数的位置
- Swift利用inout交换两个数的位置
- 两个数的交换
- 两个数的交换
- 两个数的交换
- 两个数的交换
- 交换十六进制数
- 交换两个数的值
- 交换两个数的值
- 交换两个数的算法
- 关于两个数的交换
- 交换两个数的值
- 交换两个数的值
- 交换两个数的值
- python 基于jieba模块进行中文分词词频统计
- SpringBoot 学习记录(六)- maven 打war 包并部署tomcat
- Spark开发-transformations操作
- C# 开源控件DockPanel 使用心得
- 二进制
- 交换两个十六进制数的位置
- java基础——数组操作
- Python reload()函数用法
- 新买的阿里云ECS基本安全运维
- HDU1108
- 【Shiro】Shiro从小白到大神(二)-Subject认证结合MySQL
- Amazon Aurora深度探索(二)
- Linux下查找固定时间内修改过的文件
- Python的方法解析顺序(MRO)