package util;

import java.nio.ByteBuffer;

public class ByteUtils {

	/*
	 * Taken from <a href="https://stackoverflow.com/a/4485196">StackOverflow</a>
	 */
	public static byte[] longToBytes(long x) {
		ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
		buffer.putLong(x);
		return buffer.array();
	}

	/*
	 * Taken from <a href="https://stackoverflow.com/a/4485196">StackOverflow</a>
	 */
	public static long bytesToLong(byte[] bytes) {
		ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
		buffer.put(bytes);
		buffer.flip();//need flip
		return buffer.getLong();
	}
}
