Basic implementation of Binary struct parsing

This commit is contained in:
Ziver Koc 2016-01-31 15:13:07 +01:00
parent da54bc8db5
commit b7bedc94cd
5 changed files with 123 additions and 6 deletions

View file

@ -307,6 +307,25 @@ public class Converter {
return (int)(b & 0xff);
}
/**
* Converts a dynamic sized byte array to a integer
*
* @param b is the byte array of size 1-4
* @return the int value of the byte array
*/
public static int toInt(byte[] b){
int i = 0;
switch (b.length){
default:
case 4: i |= 0xFF000000 & (b[3] << 24);
case 3: i |= 0x00FF0000 & (b[2] << 16);
case 2: i |= 0x0000FF00 & (b[1] << 8);
case 1: i |= 0x000000FF & b[0]; break;
case 0: break;
}
return i;
}
/**
* Converts a Integer to a BitSet
*