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 ?

有帮助吗?

解决方案

return (twoByte[0] & 0xff) + ((twoByte[1] & 0xff) << 8)

gives the correct result, interpreting the two bytes as unsigned number.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top