#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OLDTEST 0
typedef unsigned char INT8U; /* 无符号8位整型 */
typedef INT8U* PINT8U; /* 无符号8位整型指针 */
typedef unsigned short INT16U; /* 无符号16位整型 */
typedef unsigned int INT32U; /* 无符号32位整型 */
typedef unsigned long long INT64U; /* 无符号64位整型 */
static void INT8U_ConvertTo_Other(INT8U* pu8Data, INT8U u8BigEndian, INT8U* pu8Dst, INT8U u8Len)
{
INT8U u8Index = 0;
if(1 == u8BigEndian)
{
for(u8Index=0; u8Index<u8Len; u8Index++)
{
*pu8Dst++ = pu8Data[u8Index];
}
}
else
{
for(u8Index=u8Len; u8Index > 0; u8Index--)
{
*pu8Dst++ = pu8Data[u8Index-1];
}
}
}
int main(void)
{
INT8U u8Arr[8] = {0x12,0x34,0x56,0x78,0x87,0x65,0x43,0x21};
INT16U u16Data1 = 0; // 0x1234;
INT32U u32Data1 = 0; // 0x1234;
UINT64 u64Data1 = 0; // 0x1234567890;
INT8U_ConvertTo_Other(u8Arr, 1, (INT8U*)&u16Data1, sizeof(u16Data1));
printf("%x\n", u16Data1);
INT8U_ConvertTo_Other(u8Arr, 0, (INT8U*)&u16Data1, sizeof(u16Data1));
printf("%x\n", u16Data1);
INT8U_ConvertTo_Other(u8Arr, 1, (INT8U*)&u32Data1, sizeof(u32Data1));
printf("%x\n", u32Data1);
INT8U_ConvertTo_Other(u8Arr, 0, (INT8U*)&u32Data1, sizeof(u32Data1));
printf("%x\n", u32Data1);
INT8U_ConvertTo_Other(u8Arr, 1, (INT8U*)&u64Data1, sizeof(u64Data1));
printf("%x\n", u64Data1);
INT8U_ConvertTo_Other(u8Arr, 0, (INT8U*)&u64Data1, sizeof(u64Data1));
printf("%x\n", u64Data1);
return 0;
}