java 基本数据型之间的转换
java long转换成Bytes
Java
public static byte[] longToBytes(long primitive) {
ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
buffer.putLong(primitive);
return buffer.array();
}
java Byte转换成long
Java
public static long bytesToLong(byte[] array) {
ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE);
buffer.put(array);
buffer.flip();
long value = buffer.getLong();
return value;
}
版权声明:如无特殊标注,文章均为本站原创,转载时请以链接形式注明文章出处。
评论