#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OLDTEST 0
typedef unsigned char int8u; /* Unsigned 8-bit integer */
typedef int8u* PINT8U; /* Unsigned 8-bit integer pointer */
typedef unsigned short int16u; /* Unsigned 16-bit integer */
typedef unsigned int int32u; /* Unsigned 32-bit integer */
typedef unsigned long long int64u; /* Unsigned 64-bit integer */
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;
}
byte to int type