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