13,825
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
unsigned int cwd(unsigned short x)
{
return ((x & 0x0f00) << 8) | (x & 0x0f) | ((x & 0xf000) << 12) | ((x & 0x00f0) << 4);
}
unsigned long long cdq(unsigned int x)
{
return cwd(x) | (long long)cwd(x >> 16) << 32;
}
int main()
{
unsigned short x = 9999;
unsigned int y = 2147483645;
printf("%04x -> %08x\n", x, cwd(x));
printf("%08x - > %016llx\n", y, cdq(y));
return 0;
}
union {
WORD w;
struct {
WORD a : 4;
WORD b : 4;
WORD c : 4;
WORD d : 4;
};
} x;
x.w = 9999;
String s;
s.printf(TEXT("0x%02X 0x%02X 0x%02X 0x%02X"), x.d, x.c, x.b, x.a);
WORD a = 9999;
String s;
for (int i = 12; i >= 0; i -= 4)
s += ((i == 12) ? "0x" : " 0x") + IntToHex(a >> i & 0x0f, 2);
WORD a = 9999;
String s;
for (int i = 0; i < 4; i++) {
s = " 0x" + IntToHex(a & 0x0f, 2) + s;
a >>= 4;
}
s = s.TrimLeft();