문제

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