64,662
社区成员
发帖
与我相关
我的任务
分享
union st
{
unsigned short s;
unsigned char a[2];
} v1;
unsigned char a[2] = {0x2f,0x3e }; // {0xe2,0xf3}
v1.a[0]=a[1];
v1.a[1]=a[0];
v1.s = ((v1.s << 4) | (v1.s>>12));
cout << hex << (short)v1.a[0] << hex << (short)v1.a[1] << endl;
#include <stdio.h>
int ROR(int v,unsigned char b) {
__asm {
push ecx
mov eax,v
mov cl,b
ror eax,cl
pop ecx
}
}
void main() {
printf("0x%08x\n",ROR(0x12345678,4));
}
//0x81234567
char a[2]= {0x2f,0x3e };
unsigned short *tmpShorta;
unsigned short tmpShortb=0;
char b[2];
tmpShorta = (unsigned short*)a;
tmpShortb= *tmpShorta/16 + *tmpShorta%16*0x1000;
memcpy(b,&tmpShortb,sizeof(b));
移位可以看做是乘除法,十六进制移位就是乘除16
unsigned short *p = (unsigned short *)a;
*p = (*p >> 4) | ((*p & 0x0F) << 12);