Java te 바이트 数组之间相互转换 数组之间相互转换, 刚刚写的
패키지 cn.teaey.utils; import java.nio.charset.charset; public class byteutil {public static byte [] getbytes (짧은 데이터) {byte [] bytes = new Byte [2]; 바이트 [0] = (바이트) (데이터 & 0xff); 바이트 [1] = (바이트) ((데이터 & 0xff00) >> 8); 반환 바이트; } public static byte [] getBytes (char data) {byte [] bytes = new Byte [2]; 바이트 [0] = (바이트) (데이터); 바이트 [1] = (바이트) (데이터 >> 8); 반환 바이트; } public static byte [] getBytes (int data) {byte [] bytes = new Byte [4]; 바이트 [0] = (바이트) (데이터 & 0xff); 바이트 [1] = (바이트) ((데이터 & 0xff00) >> 8); 바이트 [2] = (바이트) ((데이터 & 0xff0000) >> 16); 바이트 [3] = (바이트) ((데이터 & 0xff000000) >> 24); 반환 바이트; } public static byte [] getBytes (긴 데이터) {byte [] bytes = new Byte [8]; 바이트 [0] = (바이트) (데이터 & 0xff); 바이트 [1] = (바이트) ((데이터 >> 8) & 0xff); 바이트 [2] = (바이트) ((데이터 >> 16) & 0xff); 바이트 [3] = (바이트) ((데이터 >> 24) & 0xff); 바이트 [4] = (바이트) ((데이터 >> 32) & 0xff); 바이트 [5] = (바이트) ((데이터 >> 40) & 0xff); 바이트 [6] = (바이트) ((데이터 >> 48) & 0xff); 바이트 [7] = (바이트) ((데이터 >> 56) & 0xff); 반환 바이트; } public static byte [] getBytes (float data) {int intbits = float.flooattointBits (data); 반환 getbytes (Intbits); } public static bd 반환 getbytes (Intbits); } public static byte [] getBytes (문자열 data, string charsetname) {charset charset = charset.forname (charsetname); return data.getBytes (charset); } public static byte [] getBytes (문자열 data) {return getBytes (data, "gbk"); } public static short getshort (byte [] bytes) {return (short) ((0xff & bytes [0]) | (0xff00 & (바이트 [1] << 8)); } public static char getchar (byte [] bytes) {return (char) ((0xff & bytes [0]) | (0xff00 & (바이트 [1] << 8)); } public static int getint (byte [] bytes) {return (0xff & bytes [0]) | (0xff00 & (바이트 [1] << 8)) | (0xff0000 & (바이트 [2] << 16)) | (0xff000000 & (바이트 [3] << 24)); } public static long getLong (byte [] bytes) {return (0xffl & (long) 바이트 [0]) | (0xff00l & ((long) 바이트 [1] << 8) | (0xff0000l & ((long) 바이트 [2] << 16)) | (0xff000000L & ((long) 바이트 [3] << 24)) | (0xff00000000L & ((long) 바이트 [4] << 32)) | (0xff0000000000L & ((long) 바이트 [5] << 40)) | (0xff000000000000L & ((Long) 바이트 [6] << 48)) | (0xff00000000000000L & ((long) 바이트 [7] << 56)); } public static float getfloat (byte [] bytes) {return float.intbitstofloat (getint (bytes)); } public static double getDouble (byte [] bytes) {long l = getLong (bytes); System.out.println (l); Double.longbitstodouble (L)을 반환합니다. } public static string getstring (byte [] bytes, string charsetname) {return new String (bytes, charset.forname (charsetname)); } public static string getstring (byte [] bytes) {return getString (bytes, "gbk"); } public static void main (String [] args) {Short S = 122; int i = 122; 긴 l = 1222222; char c = 'a'; float f = 122.22f; 이중 D = 122.22; 문자열 string = "我是好孩子"; System.out.println (s); System.out.println (i); System.out.println (l); System.out.println (C); System.out.println (f); System.out.println (d); System.out.println (문자열); System.out.println ( "**************"); System.out.println (getshort (getBytes (s))); System.out.println (getint (getbytes (i))); System.out.println (getLong (getBytes (l))); System.out.println (getchar (getbytes (c))); System.out.println (getfloat (getbytes (f))); System.out.println (getDouble (getBytes (d))); System.out.println (GetString (getBytes (String))); }}以上这篇 Java a 바이트 数组之间相互转换方法就是小编分享给大家的全部内容了 数组之间相互转换方法就是小编分享给大家的全部内容了 数组之间相互转换方法就是小编分享给大家的全部内容了, 希望能给大家一个参考, 也希望大家多多支持武林网。