0
点赞
收藏
分享

微信扫一扫

android开发通过ByteBuffer实现基本数据类型转换

米小格儿 2022-05-16 阅读 150
public static long bytesToLong(byte[] bytes) {
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.put(bytes, 0, bytes.length);
buffer.flip();
return buffer.getLong();
}

public static int bytesToInt(byte[] bytes) {
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.put(bytes, 0, bytes.length);
buffer.flip();
return buffer.getInt();
}

public static byte[] longToBytes(long num) {
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.putLong(num);
buffer.flip();
return buffer.array();
}




举报

相关推荐

0 条评论