更新时间:2021-07-08 GMT+08:00
编程实例
实例描述
对数据实现位操作,本实例实现如下功能:
- 某一标志位置1。
- 获取标志位为1的最高bit位。
- 某一标志位清0。
- 获取标志位为1的最低bit位。
编程示例
#include "los_bitmap.h" #include "los_printf.h" static UINT32 Bit_Sample(VOID) { UINT32 flag = 0x10101010; UINT16 pos; dprintf("\nBitmap Sample!\n"); dprintf("The flag is 0x%8x\n", flag); pos = 8; LOS_BitmapSet(&flag, pos); dprintf("LOS_BitmapSet:\t pos : %d, the flag is 0x%0+8x\n", pos, flag); pos = LOS_HighBitGet(flag); dprintf("LOS_HighBitGet:\t The highest one bit is %d, the flag is 0x%0+8x\n", pos, flag); LOS_BitmapClr(&flag, pos); dprintf("LOS_BitmapClr:\t pos : %d, the flag is 0x%0+8x\n", pos, flag); pos = LOS_LowBitGet(flag); dprintf("LOS_LowBitGet:\t The lowest one bit is %d, the flag is 0x%0+8x\n\n", pos, flag); return LOS_OK; }
结果验证
编译运行得到结果:
Bitmap Sample! The flag is 0x10101010 LOS_BitmapSet: pos : 8, the flag is 0x10101110 LOS_HighBitGet:The highest one bit is 28, the flag is 0x10101110 LOS_BitmapClr: pos : 28, the flag is 0x00101110 LOS_LowBitGet: The lowest one bit is 4, the flag is 0x00101110
父主题: 位操作