博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
把一个无符号16bit的数像镜面反射一样颠倒一下
阅读量:7282 次
发布时间:2019-06-30

本文共 792 字,大约阅读时间需要 2 分钟。

下面这个函数是把一个无符号16bit的数像镜面反射一样颠倒一下。

该函数是NXP(飞思卡尔)的 S32DS IDE中提供的SDK中的一个官方代码:

1 static inline uint16_t REV_BIT_16(uint16_t value) 2 { 3     uint8_t i; 4     uint16_t ret = 0U; 5  6     for (i = 0U; i < 8U; i++) 7     { 8         ret |= (uint16_t)((((value >> i) & 1U) << (15U - i)) | (((value << i) & 0x8000U) >> (15U - i))); 9     }10 11     return ret;12 }

使用S32DS创建普通的C语言的工程。选择CDT Internal Builer(否者编译会错误)。

某数:
‭0b0001001000110100‬
将该数颠倒以后:
‭0b0010110001001000‬

另外还有比较特殊的set和clear:

1     result_set |= (mask); /* bits setting using masking. when the bit in mask is 1, the corresponding bit is to be set */2     result_clear &= (~(mask)); /* bits clearing using masking. when the bit in mask is 1, the corresponding bit is to be cleared */

 

转载于:https://www.cnblogs.com/praiseslow/p/10380507.html

你可能感兴趣的文章
UBUNTU tftp 配置
查看>>
利用runtime给系统类添加动态属性
查看>>
通讯录管理系统(C语言)
查看>>
PHP类与继承
查看>>
Proxifier突破代理服务器上网的限制
查看>>
Oracle(ERROR SP2-0642)
查看>>
反射加强(一)
查看>>
The class has no identifier property
查看>>
碰到的一些面试问题
查看>>
APICloud框架——总结一下最近开发APP遇到的一些问题 (二)
查看>>
python day04
查看>>
JVM的内存区域划分
查看>>
MySQL基础
查看>>
1595:Symmetry
查看>>
你应该知道的大数据领域12大动向
查看>>
R-CNN for Small Object Detection
查看>>
IF函数多个条件判断及嵌套
查看>>
代码搬移
查看>>
ajax请求code:200但是进入error函数
查看>>
软件图标显示不正常的问题
查看>>