反转字节序
/* * 反转四字节整型字节序 */ unsigned int *ReverseWord(unsigned int *word) { unsigned char *byte, temp; byte = (unsigned char *)word; temp = byte[0]; byte[0] = byte[3]; byte[3] = temp; temp = byte[1]; byte[1] = byte[2]; byte[2] = temp; return word; }
/* * 反转字节序 */ void *ReverseByteOrder(void *p, unsigned int len) { unsigned int i; unsigned char *bytes, temp; bytes = (unsigned char *)p; for (i = 0; i < len / 2; i++) { temp = bytes[i]; bytes[i] = bytes[len - 1 - i]; bytes[len - 1 - i] = temp; } return p; }