G
gamehack
Hello all,
Sorry for asking too much but I've been playing with some code and just
wrote this function:
void reverse(uint32_t num)
{
uint8_t bytes[4];
printf("sizeof(uint8_t) is %d and bits per byte is: %d\n",
sizeof(uint8_t), CHAR_BIT);
bytes[0] = (uint8_t) ((num & 0x000000FF) >> 0);
bytes[1] = (uint8_t) ((num & 0x0000FF00) >> 8);
bytes[2] = (uint8_t) ((num & 0x00FF0000) >> 16);
bytes[3] = (uint8_t) ((num & 0xFF000000) >> 24);
printf("Number in memory: %#x %#x %#x %#x\nActual num is: %#x\n",
bytes[3], bytes[2], bytes[1], bytes[0], num);
}
And on my little endian machine it outputs:
sizeof(uint8_t) is 1 and bits per byte is: 8
Number in memory: 0xaa 0xbb 0xcc 0xdd
Actual num is: 0xaabbccdd
Surely the number in memory has to be 0xdd 0xcc 0xbb 0xaa... I'm doing
some really stupid mistake but I can't see it.
Thanks
Sorry for asking too much but I've been playing with some code and just
wrote this function:
void reverse(uint32_t num)
{
uint8_t bytes[4];
printf("sizeof(uint8_t) is %d and bits per byte is: %d\n",
sizeof(uint8_t), CHAR_BIT);
bytes[0] = (uint8_t) ((num & 0x000000FF) >> 0);
bytes[1] = (uint8_t) ((num & 0x0000FF00) >> 8);
bytes[2] = (uint8_t) ((num & 0x00FF0000) >> 16);
bytes[3] = (uint8_t) ((num & 0xFF000000) >> 24);
printf("Number in memory: %#x %#x %#x %#x\nActual num is: %#x\n",
bytes[3], bytes[2], bytes[1], bytes[0], num);
}
And on my little endian machine it outputs:
sizeof(uint8_t) is 1 and bits per byte is: 8
Number in memory: 0xaa 0xbb 0xcc 0xdd
Actual num is: 0xaabbccdd
Surely the number in memory has to be 0xdd 0xcc 0xbb 0xaa... I'm doing
some really stupid mistake but I can't see it.
Thanks