Macro implementation Size-end conversion

Source: Internet
Author: User
Macro implementation Size-end conversion
/*  define multiline macros after each line with a ' \ '/
#define SW16 (x) \ (short) ((short)
        (x) & (short) 0x00ffu) << 8 | \< c5/> ((short) (x) & (short) 0xff00u) >> 8))

Suppose X=0xaabb
(short) (x) & (short) 0x00ffu) and 16-digit high 8-bit 0 0X00BB

Then <<8 to the left 8-bit lower 8-bit into a high 8-bit low 8-bit 0 results for 0XBB00


((short) (x) & (short) 0xff00u) >> 8)) The exact opposite result is 0X00AA


Two results again or one 0xbb00 | The 0X00AA is 0xbbaa.


macro implements size and spin network byte order


typedef unsigned short int uint16;
typedef unsigned long int uint32;


#define BIGLITTLESWAP16 (a)        (((UInt16) (a) & 0xff00) >> 8) | ((
                                                       uint16) (a) & 0X00FF) << 8) c4/> #define BIGLITTLESWAP32 (a)        ((UInt32) (a) & 0xff000000) >>) |
                                                       ((UINT32) (a) & 0x00ff0000 ) >> 8) | \ ((
                                                       UInt32) (a) & 0x0000ff00) << 8 | ((
                                                       uint32) (a) & 0x000000ff) << 24)


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.