|
|
|
|
@ -25,15 +25,28 @@ public class ByteConverter {
|
|
|
|
|
//Integer
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param bite bite to convert
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public static int bytesToInt(byte bite){
|
|
|
|
|
byte[] bytes = {bite};
|
|
|
|
|
return bytesToInt(bytes, ByteOrder.LITTLE_ENDIAN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param bytes bytes to convert
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public static int bytesToInt(byte[] bytes){
|
|
|
|
|
return bytesToInt(bytes, ByteOrder.LITTLE_ENDIAN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param bytes bytes to convert
|
|
|
|
|
* @param byteOrder order of the bytes
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public static int bytesToInt(byte[] bytes, ByteOrder byteOrder){
|
|
|
|
|
byte[] bites = convertBytesToNum(bytes,byteOrder, IntegerSize);
|
|
|
|
|
return ByteBuffer.wrap(bites).order(byteOrder).getInt();
|
|
|
|
|
@ -144,7 +157,7 @@ public class ByteConverter {
|
|
|
|
|
* @param i the integer to be converted
|
|
|
|
|
* @param size Size that the byte array should be
|
|
|
|
|
* @param byteOrder the order that the bytes should be ie Big Endian
|
|
|
|
|
* @return
|
|
|
|
|
* @return bytes array
|
|
|
|
|
*/
|
|
|
|
|
public static byte[] intToBytes(int i ,int size, ByteOrder byteOrder){
|
|
|
|
|
ByteBuffer buffer = ByteBuffer.allocate(IntegerSize);
|
|
|
|
|
@ -171,7 +184,7 @@ public class ByteConverter {
|
|
|
|
|
* @param i the Long to be converted
|
|
|
|
|
* @param size Size that the byte array should be
|
|
|
|
|
* @param byteOrder the order that the bytes should be ie Big Endian
|
|
|
|
|
* @return
|
|
|
|
|
* @return byte array
|
|
|
|
|
*/
|
|
|
|
|
public static byte[] longToBytes(long i ,int size, ByteOrder byteOrder){
|
|
|
|
|
ByteBuffer buffer = ByteBuffer.allocate(LongSize);
|
|
|
|
|
@ -198,7 +211,7 @@ public class ByteConverter {
|
|
|
|
|
* @param i the Short to be converted
|
|
|
|
|
* @param size Size that the byte array should be
|
|
|
|
|
* @param byteOrder the order that the bytes should be ie Big Endian
|
|
|
|
|
* @return
|
|
|
|
|
* @return byte array
|
|
|
|
|
*/
|
|
|
|
|
public static byte[] shortToBytes(short i ,int size, ByteOrder byteOrder){
|
|
|
|
|
ByteBuffer buffer = ByteBuffer.allocate(ShortSize);
|
|
|
|
|
@ -225,7 +238,7 @@ public class ByteConverter {
|
|
|
|
|
* @param i the Char to be converted
|
|
|
|
|
* @param size Size that the byte array should be
|
|
|
|
|
* @param byteOrder the order that the bytes should be ie Big Endian
|
|
|
|
|
* @return
|
|
|
|
|
* @return byte array
|
|
|
|
|
*/
|
|
|
|
|
public static byte[] charToBytes(char i ,int size, ByteOrder byteOrder){
|
|
|
|
|
ByteBuffer buffer = ByteBuffer.allocate(CharSize);
|
|
|
|
|
|