Java Bytes 操作和类型转换
public byte[] longToBytes(long x) { ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(x); return buffer.array(); } public long bytesToLong(byte[] bytes) { ByteBuffer buffer = ByteBuffer.allocate(8); buffer.put(bytes); buffer.flip();// need flip return buffer.getLong(); } public static final byte[] intToByteArray(int value) { return new byte[] { (byte)(value >>> 24), (byte)(value >>> 16), (byte)(value >>> 8), (byte)value}; } static byte[] concatByteArray(byte[] a, byte[] b) { byte[] c = new byte[a.length + b.length]; System.arraycopy(a, 0, c, 0, a.length); System.arraycopy(b, 0, c, a.length, b.length); return c; } public static byte[] GetBytes(int value) { ByteBuffer buffer = ByteBuffer.allocate(4).order(ByteOrder.nativeOrder()); buffer.putInt(value); return buffer.array(); } public static long getUnsignedInt(int x) { return x & 0x00000000ffffffffL; }
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了