conversion between int type and tyte[] in Java and byte[] Merge

Source: Internet
Author: User

Java Displacement-based int type and tyte[] conversion between [Java] view plaincopy/*** Displacement-based int converted to byte[] *@paramint number *@returnbyte[]*/     Public Static byte[] Inttobyte (intNumber ) {      byte[] Abyte =New byte[4]; //& and (and), performs a Boolean algebra on the corresponding bit in two integer operands, and two bits are 1 o'clock output 1, otherwise 0. Abyte[0] = (byte) (0xFF &Number ); //">>" right shift, if positive is a high 0, if negative, high 1ABYTE[1] = (byte) ((0xff00 & number) >> 8); abyte[2] = (byte) ((0xff0000 & number) >> 16); abyte[3] = (byte) ((0xff000000 & number) >> 24); returnAbyte; }    /*** Displacement-based byte[] converted to int *@parambyte[] Bytes *@returnint Number*/     Public Static intBytestoint (byte[] bytes) {      intNumber = Bytes[0] & 0xFF; //"|=" bitwise OR assignment. Number |= ((Bytes[1] << 8) & 0XFF00); number|= ((bytes[2] <<) & 0xFF0000); number|= (bytes[3 <<) & 0xff000000); returnNumber ; Java arraycopy Merge two x byte[] array [Java] View plaincopy/*** Combining two byte[] arrays based on Arraycopy *@parambyte[] Bytes1 *@parambyte[] Bytes2 *@returnbyte[] Bytes3*/       Public   byte[] Combinetowbytes (byte[] bytes1,byte[] bytes2) {              byte[] Bytes3 =New byte[bytes1.length+Bytes2.length]; System.arraycopy (Bytes1,0,bytes3,0, bytes1.length); System.arraycopy (Bytes2,0, bytes3,bytes1.length,bytes2.length); returnBytes3; }  

conversion between int type and tyte[] in Java and byte[] Merge

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.