byte[of int in JAVA and C # Communication]

Source: Internet
Author: User

In the Java and C # communication due to two kinds of non-soket language int type, such as when doing a packet header to confirm that the data length requires a fixed number of bytes stored in an int type of data sent will not read the same data.

convert int to byte[in Java]

1 /**2 * Dump Data of the Int32 type into a byte array of 4 bytes3      * @parami:int32 Types of data4      * @returnreturns a byte array of 4 bytes in size5      */6      Public Static byte[] Convertinttobytearray (inti)7     {8       byte[] Arry =New byte[4];9ARRY[3] = (byte) ((((I & 0xff000000) >>) & 0xFF); TenARRY[2] = (byte) (((& 0x00ff0000) >> 0xFF) &);  OneARRY[1] = (byte) ((((I & 0x0000FF00) >> 8) & 0xFF);  AArry[0] = (byte) ((I & 0x000000ff) & 0xFF); -       returnArry; -}

Read in C #

byte New byte [404, socketflags.none); int 0);

byte[of int in JAVA and C # Communication]

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.