比如0x12 ——>0001 0010 反转后变成 0100 1000 即0x48
static unsigned char buf=0x12,buf1=0;
static int m,n;for(m=7,n=0;m-n>0;m--,n++)
{
buf1 |=((buf&(0x1<<n))<<m-n)|((buf&(0x80>>n))>>m-n);
}
buf=buf1;
将两字节short类型数高低字节取出来:
unsigned short a = 0x9867 char buf[2]; memcpy(buf,&a,2); |
int a = 0x9867, low, high; low = (char) a; high = (a >> 8); 对于后一个,下面这样写移植性更好,不然在在老式的编译器上(比如TC)有问题: high = (a >> 8) & 0x00FF; |