#include <stdio.h>
/* 8位数字高低位调换 */
unsigned char ltoh(unsigned char data)
{
int i = 0;
unsigned char buf = 0;
for(i = 0; i < 8; i++) {
buf |= (((data >> i) & 0x1) << (7 - i));
printf("(((data >> i) & 0x1) << (7 - i)) = 0x%02x\n", ((data >> i) & 0x1) << (7 - i));
}
printf("data=0x%02x, buf=0x%02x\n", data, buf);
return buf;
}
int main(void)
{
ltoh(0x0f);
return 0;
}
C语言 8位数字 unsigned char类型高低位对换
最新推荐文章于 2023-09-01 03:45:45 发布