return (twoByte[0] & 0xff) + ((twoByte[1] & 0xff) << 8)
gives the correct result, interpreting the two bytes as unsigned number.
Question
First of all I have a couple hours experience with java, so if its a bit easy question sorry about that.
Now, I have a byte array with size 2 And I want to get corresponding integer value from it. I use little endian notation. Here is my code:
public static int convertInt(byte[] twoByte){
//TODO
}
Is there anyone to help me ?
Solution
return (twoByte[0] & 0xff) + ((twoByte[1] & 0xff) << 8)
gives the correct result, interpreting the two bytes as unsigned number.