本文主要是介绍C语言 LSB->MSB,MSB->LSB转换,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
32位整型数据bit位高低转换
unsigned int reverse(register unsigned int x)
{x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));return((x >> 16) | (x << 16));}
16位整型数据bit位高低转换
unsigned short reverse(unsigned short x)
{x = (((x & 0xaaaa) >> 1) | ((x & 0x5555) << 1));x = (((x & 0xcccc) >> 2) | ((x & 0x3333) << 2));x = (((x & 0xf0f0) >> 4) | ((x & 0x0f0f) << 4));return((x >> 8) | (x << 8));}
8位整型数据bit位高低转换
uint8_t reverse(uint8_t x)
{x = (((x & 0xaa) >> 1) | ((x & 0x55) << 1)); x = (((x & 0xcc) >> 2) | ((x & 0x33) << 2)); return((x >> 4) | (x << 4));
}
这篇关于C语言 LSB->MSB,MSB->LSB转换的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!