This code is supposedly convert byte array into int. But when I compile I get an error:
non-static variable output cannot be referenced from a static context
public class BitArrayToInt{
byte[] output = {
(byte)0x00, (byte)0xFF
};
int value;
public static void main(String args[]){
System.out.println(byteArrayToInt(output));
}
public static int byteArrayToInt(byte[] b){
return byteArrayToInt(b, 0);
}
private static int byteArrayToInt(byte[] b, int offset){
int value = 0;
for(int i=0; i<4; i++){
int shift = (4 - 1 - i)*8;
value += (b[i + offset] & 0x000000FF) << shift;
}
return value;
}
}