Objective C-High and low bit conversion when interacting with Android:

Source: Internet
Author: User


In the process of interacting with Android, because Android is read from low to High, iOS is read from high to low, so the interactive data needs to be converted.


/* * Convert big endian to little endian in C */uint16_t swap_uint16 (uint16_t val); int16_t swap_int16 (int16_t val); UIn t32_t Swap_uint32 (uint32_t val); int32_t Swap_int32 (int32_t val); int64_t Swap_int64 (int64_t val); uint64_t Swap_uint64 (uint64_t val);//////////////////////////////////////////////////////////////////////////////////////////////// //////! Byte Swap unsigned shortuint16_t swap_uint16 (uint16_t val) {return (Val << 8) | (Val >> 8);} //! Byte swap shortint16_t swap_int16 (int16_t val) {return (Val << 8) | (Val >> 8) & 0xFF);} //! Byte Swap unsigned intuint32_t swap_uint32 (uint32_t val) {val = ((val << 8) & 0xff00ff00) |    (Val >> 8) & 0XFF00FF); Return (Val << 16) | (Val >> 16);} //! Byte swap intint32_t Swap_int32 (int32_t val) {val = ((val << 8) & 0xff00ff00) |    (Val >> 8) & 0XFF00FF); Return (Val << 16) | ((Val >>) & 0xFFFF);} int64_t swap_inT64 (int64_t val) {val = ((val << 8) & 0xff00ff00ff00ff00ull) |    (Val >> 8) & 0x00ff00ff00ff00ffull); val = ((Val <<) & 0xffff0000ffff0000ull) |    (Val >>) & 0x0000ffff0000ffffull); val = (val << 32) |    ((Val >> +) & 0xFFFFFFFFULL); return Val;} uint64_t Swap_uint64 (uint64_t val) {val = ((val << 8) & 0xff00ff00ff00ff00ull) |    (Val >> 8) & 0x00ff00ff00ff00ffull); val = ((Val <<) & 0xffff0000ffff0000ull) |    (Val >>) & 0x0000ffff0000ffffull); val = (val << 32) |    (Val >> 32); return Val;}


Call:

UInt64 recordtime = [[NSDate date] timeintervalsince1970]*1000; UInt64 value = Swap_uint64 (recordtime);







Related Article

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.