Reformat and clean up "tools" package
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
package tools;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Shavit
|
||||
*/
|
||||
public class LongTool {
|
||||
|
||||
|
||||
// Converts 8 bytes to a long.
|
||||
public static long BytesToLong(byte[] aToConvert)
|
||||
{
|
||||
if(aToConvert.length != Long.BYTES)
|
||||
{
|
||||
public static long BytesToLong(byte[] aToConvert) {
|
||||
if (aToConvert.length != Long.BYTES) {
|
||||
throw new IllegalArgumentException(String.format("Size of input should be %d", (Long.SIZE / 8)));
|
||||
}
|
||||
|
||||
long nResult = 0;
|
||||
|
||||
for(int i = 0; i < Long.BYTES; i++)
|
||||
{
|
||||
for (int i = 0; i < Long.BYTES; i++) {
|
||||
nResult <<= Byte.SIZE;
|
||||
nResult |= (aToConvert[i] & 0xFF);
|
||||
}
|
||||
@@ -26,12 +22,10 @@ public class LongTool {
|
||||
}
|
||||
|
||||
// Converts a long to 8 bytes.
|
||||
public static byte[] LongToBytes(long nToConvert)
|
||||
{
|
||||
public static byte[] LongToBytes(long nToConvert) {
|
||||
byte[] aBytes = new byte[Long.BYTES];
|
||||
|
||||
for(int i = aBytes.length - 1; i >= 0; i--)
|
||||
{
|
||||
for (int i = aBytes.length - 1; i >= 0; i--) {
|
||||
aBytes[i] = (byte) (nToConvert & 0xFF);
|
||||
nToConvert >>= Byte.SIZE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user