例は次のとおりです。
public class dataTypechangehelper { / ** *シングルバイトバイトを32ビットint * * @param b * byte * @return convert result * / public static int unsignedbytetoint(byte b){return(int)b&0xff; } / ** *シングルバイトバイトを16進数に変換 * * @param b * byte * @return convert result * / public static string bytetohex(byte b){int i = b&0xff; return integer.tohexstring(i); } / ** * 4バイトの配列を32ビットint * * @param buf * bytesバッファに変換 * @param byte []の位置 * @return convert result * / public static long unsigned4bytestoint(byte [] buf、int pos){int firstbyte = 0; int secondbyte = 0; int shuldbyte = 0; int 4thbyte = 0; int index = pos; firstbyte =(0x000000ff&((int)buf [index])); secondbyte =(0x000000ff&((int)buf [index + 1])); ThirdByte =(0x000000ff&((int)buf [index + 2])); 4thbyte =(0x000000ff&((int)buf [index + 3])); index = index + 4; return((long)(firstbyte << 24 | secondbyte << 16 | thirdbyte << 8 | fourthbyte))&0xffffffl; } / ** * 16ビットショートアレイに変換 * * @param s * short * @return byte []長さは2 * * * / public static byte [] shorttobytearray(short s){byte []ターゲット= new byte [2]; for(int i = 0; i <2; i ++){int offset =(targets.length -1 -i) * 8;ターゲット[i] =(byte)((s >>> offset)&0xff); }ターゲットを返します。 } / ** *長さ4 * * * @return byte [] * * / public static byte [] inttobytearray(int s){byte []ターゲット= new byte [2]; for(int i = 0; i <4; i ++){int offset =(targets.length -1 -i) * 8;ターゲット[i] =(byte)((s >>> offset)&0xff); }ターゲットを返します。 } / ** * long to byte [] * * @param s * long * @return byte [] * * / public static byte [] longtobytearray(long s){byte []ターゲット= new byte [2]; for(int i = 0; i <8; i ++){int offset =(targets.length -1 -i) * 8;ターゲット[i] =(byte)((s >>> offset)&0xff); }ターゲットを返します。 } / ** 32ビットint to byte []* / public static byte [] int2byte(int res){byte []ターゲット= new byte [4];ターゲット[0] =(byte)(res&0xff); //最低桁ターゲット[1] =(byte)((res >> 8)&0xff); // 2番目の低指標ターゲット[2] =(byte)((res >> 16)&0xff); // 2番目の高位置ターゲット[3] =(buyte)ターゲットを返します。 } / ** *長さ2のバイト配列を16ビットint * * @param res * byte [] * @return int * * / public static int byte2int(byte [] res){// res = inversionbyte(res); //バイトデータが24ビットの残り0x?000000にシフトし、8ビットを0x00に右にシフトしました?? 00000 intターゲット=(res [0]&0xff)| ((res [1] << 8)&0xff00); // |周囲または返品のターゲットを示します。 }}上記は、Java Byte Arrayとint、long、short、byteの変換実装方法の完全な内容です。誰もがwulin.comをもっとサポートすることを願っています〜