高低位字节互换

#include <iostream>
#include <iomanip>

using namespace std;
int main()
{
	unsigned short A =0xABCD;
	unsigned short B,C,D;
	
	cout<<setiosflags(ios::uppercase)
		<<hex
		<<"A =0x "
		<<A<<endl;

	B = (A<<8)&0xff00;
	C = (A>>8)&0x00ff;
	D = C|B;
	cout<<"B =0x "<<B<<endl
		<<"C =0x "<<C<<endl
		<<"D =0x "<<D<<endl;
	return 0;
}

你可能感兴趣的:(高低位字节互换)