byte与int与long类型之间相互转换(好文章)

 

import java.nio.ByteBuffer;


public static int byteToInt(byte[] bytes){

    //或//return ByteBuffer.wrap(bytes).getInt();

    int number = 0;
     for(int i = 0; i < 4 ; i++){
         number += bytes[i] << i*8;
     }
     return number;
}
import java.nio.ByteBuffer;


public static long BytesToLong(byte[] buffer) {

    //或//return ByteBuffer.wrap(bytes).getLong();

    long  values = 0;   
    for (int i = 0; i < 8; i++) {    
        values <<= 8; values|= (buffer[i] & 0xff);   
    }   
    return values;  
 } 

 

参考自:

https://www.cnblogs.com/lele88lala/p/4952508.html

https://blog.csdn.net/drupe/article/details/41729873

你可能感兴趣的:(大厂任性挑,springBoot,JAVA,byte,int,long)