예는 다음과 같습니다.
공개 클래스 DataTatyPechangeHelper { / ** * 단일 바이트 바이트를 32 비트 int * * @param b * byte * @return convert * / public static int unsignedByTetoint (byte b) {return (int) b & 0xff; } / ** * 단일 바이트 바이트를 16 진수로 변환 * @param b * byte * @return result * / public static string bytetoHex (byte b) {int i = b & 0xff; return integer.tohexstring (i); } / ** * 4BIT 배열을 32 비트 int * * @param buf * 바이트 버퍼로 변환 * @param byte []의 위치는 변환이 시작되는 위치 * @return convert * / public static long unsigned4byTestoint (byte []] {int firstbyte = 0; int SecondByte = 0; int ThirdByte = 0; int Fourthbyte = 0; int index = pos; FirstByte = (0x000000ff & (int) buf [index])); SecondByte = (0x000000ff & (int) buf [index + 1])); ThirdByte = (0x000000ff & (int) buf [index + 2]); Fourthbyte = (0x000000ff & (int) buf [index + 3]); 색인 = 인덱스 + 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 [] targets = new Byte [2]; for (int i = 0; i <2; i ++) {int offset = (targets.length -1 -i) * 8; 대상 [i] = (byte) ((s >>> 오프셋) & 0xff); } 반환 대상; } / ** * 길이 4 * * @param s * int * @return byte [] * / public static byte [] inttobytearray (int s) {byte [] targets = new Byte [2]; for (int i = 0; i <4; i ++) {int offset = (targets.length -1 -i) * 8; 대상 [i] = (byte) ((s >>> 오프셋) & 0xff); } 반환 대상; } / ** * byte to byte [] * * @param s * long * @return byte [] * / public static byte [] longtobytearray (long s) {byte [] targets = new Byte [2]; for (int i = 0; i <8; i ++) {int offset = (targets.length -1 -i) * 8; 대상 [i] = (byte) ((s >>> 오프셋) & 0xff); } 반환 대상; } / ** 32 비트 int to byte []* / public static bd 대상 [0] = (byte) (res & 0xff); // 가장 낮은 숫자 대상 [1] = (byte) ((res >> 8) & 0xff); // 두 번째 로우 숫자 대상 [2] = (byte) ((res >> 16) & 0xff); // 두 번째 높은 위치 대상 [3] = (byte >> 24); // Highinst Joction. 반환 대상; } / ** * 길이 2의 바이트 배열을 16 비트 int * * @param res * byte [] * @return int * / public static int byte2int (byte [] res) {// res = inversionByte (res); // 바이트 데이터는 24 비트로 왼쪽으로 0x로 이동 한 다음 0x000으로 8 비트를 0x00으로 이동합니까 ?? 00000 int targets = (res [0] & 0xff) | ((res [1] << 8) & 0xff00); // | 주변 또는 반환 목표를 나타냅니다. }}위의 것은 Java Byte Array의 전환 구현 방법의 전체 내용이며 int, Long, Short, Byte가 제공합니다. 모두가 wulin.com을 더 지원하기를 바랍니다