我有一个四字节的 DWORD,我需要将其拆分为四个不同的字符。我以为我知道如何做到这一点,但每次都得到奇怪的数字。这是我的代码:
// The color memory
int32 col = color_mem[i];
// The four destination characters
char r, g, b, a;
// Copy them in advancing by one byte every time
memcpy(&r, &col, 1);
memcpy(&g, &col + 1, 1);
memcpy(&b, &col + 2, 1);
memcpy(&a, &col + 3, 1);