STM32使用自带函数实现byte逆序

  当一个8位数为0b00101110,你希望使其位逆序,即:0b01110100,可以使用__rbit()函数,此函数操作的参数为32位。示例如下:

//------------------------------------------------------------------
//	Brief	: Reverse bit order of value
//	Input	: Value to reverse
//	Output	: None
//	Return	: Reversed value
//------------------------------------------------------------------
uint8_t reverse_bit(uint8_t val)
{
	uint32_t temp;
	temp = (val << 24);
	temp = __rbit( temp );
	return (uint8_t)temp;
}

  

posted on 2015-01-14 14:42  Life's coding  阅读(858)  评论(0编辑  收藏  举报

导航