24 lines
577 B
Java
24 lines
577 B
Java
package com.alterdekim.game.utils;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
public class ByteUtils {
|
|
public static byte[] longToBytes(long l) {
|
|
byte[] result = new byte[Long.BYTES];
|
|
for (int i = Long.BYTES - 1; i >= 0; i--) {
|
|
result[i] = (byte)(l & 0xFF);
|
|
l >>= Byte.SIZE;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static long bytesToLong(byte[] b) {
|
|
long result = 0;
|
|
for (int i = 0; i < Long.BYTES; i++) {
|
|
result <<= Byte.SIZE;
|
|
result |= (b[i] & 0xFF);
|
|
}
|
|
return result;
|
|
}
|
|
}
|