converting bytes to int in Java

byte, java

Solution

return ((int)hb << 8) | ((int)lb & 0xFF);

Correct operation in all cases is left as an exercise for the student.

Problem

I need to convert 2 bytes (2's complement) into an int in Java code. how do I do it? ``` toInt(byte hb, byte lb) { } ```

Original source

Related problems