long b=99999999999999999L转换成byte[]后再转回来对不上
public class Binary { //将byte[]转换成long public long byte2Long(byte[] arr){ long num = 0; for (int i= 0; i < 8; i++) { num += (long)((arr[i]&0xff)<<i*8) ; } return num; } //将long转换成byte[] public byte[] long2Byte(long b){ byte[] bytes=new byte[8]; for (int i = 0; i < 8; i++) { bytes[i]=(byte)((b>>i*8)&0xff); } return bytes; } public static void main(String[] args) { Binary test=new Binary(); long b= 99999999999999999L; byte[] bytes=test.long2Byte(b) ; System.out.println(Arrays.toString(bytes)); System.out.println(test.byte2Long(bytes)); } }
转回来变成了1592608119