byte to int type

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.