取出高8位,然后右移8位,再取出低8位,然后左移8位,再把它们相加就可以了,代码:12345678910111213#includeunsigned short MyConvert(unsigned short sval){ return ((sval&0x00ff)<<8) + ((sval&0xff00)>>8);}int main(){ unsigned short sval = 0xabcd; printf("%d,0x%X\n", sval, sval); sval = MyConvert(sval); printf("%d,0x%X\n", sval, sval); return 0;}
{ short num16bit; char num8bit; printf("please input a 16-bit number in decimal:"); scanf("%d", &num16bit); num8bit = (char)(num16bit>>8); num16bit <<= 8; num16bit &= 0xff00; num16bit |= num8bit; printf("Flip 8-bit of this number is : %d.\n", num16bit);}